mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 05:22:02 +00:00
feat(FE-40,41): create Master Data Detail Location page
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
'use client';
|
||||
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import useSWR from 'swr';
|
||||
|
||||
import LocationForm from '@/components/pages/master-data/location/form/LocationForm';
|
||||
|
||||
import { LocationApi } from '@/services/api/master-data';
|
||||
import { isResponseSuccess } from '@/lib/api-helper';
|
||||
|
||||
const LocationDetail = () => {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
const locationId = searchParams.get('locationId');
|
||||
|
||||
const { data: location, isLoading: isLoadingLocation } = useSWR(
|
||||
locationId,
|
||||
(id: number) => LocationApi.getSingle(id)
|
||||
);
|
||||
|
||||
if (!locationId) {
|
||||
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 (!isLoadingLocation && !location) {
|
||||
router.replace('/404');
|
||||
return;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className='w-full p-4 flex flex-row justify-center'>
|
||||
{isLoadingLocation && (
|
||||
<span className='loading loading-spinner loading-xl' />
|
||||
)}
|
||||
{!isLoadingLocation && isResponseSuccess(location) && (
|
||||
<LocationForm type='detail' initialValues={location.data} />
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default LocationDetail;
|
||||
Reference in New Issue
Block a user