mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 07:45:47 +00:00
refactor(FE): Add fallback for product flag mapping on constants error
This commit is contained in:
@@ -39,8 +39,12 @@ import { cn } from '@/lib/helper';
|
|||||||
|
|
||||||
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
|
||||||
import { ConstantsApi } from '@/services/api/constants/constants';
|
import { ConstantsApi } from '@/services/api/constants/constants';
|
||||||
import type { TransformedConstants } from '@/types/api/constants/constants';
|
import type {
|
||||||
|
TransformedConstants,
|
||||||
|
ProductFlagMapping,
|
||||||
|
} from '@/types/api/constants/constants';
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
|
import { PRODUCT_FLAG_MAPPING } from '@/config/constant';
|
||||||
|
|
||||||
import { Supplier } from '@/types/api/master-data/supplier';
|
import { Supplier } from '@/types/api/master-data/supplier';
|
||||||
import Card from '@/components/Card';
|
import Card from '@/components/Card';
|
||||||
@@ -57,11 +61,24 @@ const ProductForm = ({ type = 'add', initialValues }: ProductFormProps) => {
|
|||||||
|
|
||||||
const [productFormErrorMessage, setProductFormErrorMessage] = useState('');
|
const [productFormErrorMessage, setProductFormErrorMessage] = useState('');
|
||||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||||
const { data: constants, isLoading: isLoadingConstants } = useSWR<
|
const {
|
||||||
TransformedConstants | undefined
|
data: constants,
|
||||||
>('constants', ConstantsApi.fetchTransformedConstants.bind(ConstantsApi));
|
error: constantsError,
|
||||||
|
isLoading: isLoadingConstants,
|
||||||
|
} = useSWR<TransformedConstants | undefined>(
|
||||||
|
'constants',
|
||||||
|
ConstantsApi.fetchTransformedConstants.bind(ConstantsApi),
|
||||||
|
{
|
||||||
|
shouldRetryOnError: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const productFlagMapping = constants?.product_flag_mapping ?? null;
|
const productFlagMapping: ProductFlagMapping | null = useMemo(() => {
|
||||||
|
if (constantsError || !constants) {
|
||||||
|
return PRODUCT_FLAG_MAPPING as unknown as ProductFlagMapping;
|
||||||
|
}
|
||||||
|
return constants.product_flag_mapping;
|
||||||
|
}, [constants, constantsError]);
|
||||||
|
|
||||||
const createProductHandler = useCallback(
|
const createProductHandler = useCallback(
|
||||||
async (payload: CreateProductPayload) => {
|
async (payload: CreateProductPayload) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user