mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
'use client';
|
|
|
|
import { useRouter, useSearchParams } from 'next/navigation';
|
|
import useSWR from 'swr';
|
|
|
|
import AreaForm from '@/components/pages/master-data/area/form/AreaForm';
|
|
|
|
import { AreaApi } from '@/services/api/master-data';
|
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
|
|
|
const AreaEdit = () => {
|
|
const router = useRouter();
|
|
const searchParams = useSearchParams();
|
|
|
|
const areaId = searchParams.get('areaId');
|
|
|
|
const { data: area, isLoading: isLoadingArea } = useSWR(
|
|
areaId,
|
|
(id: number) => AreaApi.getSingle(id)
|
|
);
|
|
|
|
if (!areaId) {
|
|
router.back();
|
|
|
|
return (
|
|
<div className='w-full flex flex-row justify-center items-center p-4'>
|
|
<span className='loading loading-spinner loading-xl' />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
if (!isLoadingArea && (!area || isResponseError(area))) {
|
|
router.replace('/404');
|
|
return;
|
|
}
|
|
|
|
return (
|
|
<div className='w-full p-4 flex flex-row justify-center'>
|
|
{isLoadingArea && <span className='loading loading-spinner loading-xl' />}
|
|
{!isLoadingArea && isResponseSuccess(area) && (
|
|
<AreaForm type='edit' initialValues={area.data} />
|
|
)}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default AreaEdit;
|