Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/KBDEV-1156-admin-failed-casting-email
Browse files Browse the repository at this point in the history
  • Loading branch information
elewis2 authored May 2, 2024
2 parents c439342 + 30f20f7 commit cfca3c9
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/views/NewRecordView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import './index.scss';
import React, {
ReactNode,
useCallback,
useEffect,
} from 'react';
import {
useLocation, useNavigate, useParams, useSearchParams,
Expand All @@ -17,11 +18,13 @@ import util from '@/services/util';

const VARIANT_CLASSES = ['variant', 'positionalvariant', 'categoryvariant'];

const NewRecordView = () => {
const NewRecordView = ({ modelName: propsModelName }) => {
const navigate = useNavigate();
const { pathname } = useLocation();
const [searchParams] = useSearchParams();
const { modelName } = useParams<{ modelName: string }>();
const { modelName: paramsModelName } = useParams<{ modelName: string }>();
const modelName = propsModelName || paramsModelName;

/**
* After the form is submitted/completed. Handle the corresponding redirect
*/
Expand All @@ -44,10 +47,13 @@ const NewRecordView = () => {

let innerComponent: ReactNode = null;

if (!modelName) {
navigate('/', { replace: true });
return null;
}
useEffect(() => {
if (!modelName) {
navigate('/query', { replace: true });
}
}, [modelName, navigate]);

if (!modelName) return null;

if (
VARIANT_CLASSES.includes(modelName.toLowerCase())
Expand Down

0 comments on commit cfca3c9

Please sign in to comment.