mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +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 { 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 { PRODUCT_FLAG_MAPPING } from '@/config/constant';
|
||||
|
||||
import { Supplier } from '@/types/api/master-data/supplier';
|
||||
import Card from '@/components/Card';
|
||||
@@ -57,11 +61,24 @@ const ProductForm = ({ type = 'add', initialValues }: ProductFormProps) => {
|
||||
|
||||
const [productFormErrorMessage, setProductFormErrorMessage] = useState('');
|
||||
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
|
||||
const { data: constants, isLoading: isLoadingConstants } = useSWR<
|
||||
TransformedConstants | undefined
|
||||
>('constants', ConstantsApi.fetchTransformedConstants.bind(ConstantsApi));
|
||||
const {
|
||||
data: constants,
|
||||
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(
|
||||
async (payload: CreateProductPayload) => {
|
||||
|
||||
Reference in New Issue
Block a user