mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE-40): create Nonstock Edit page
This commit is contained in:
@@ -0,0 +1,49 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
|
||||||
|
import NonstockForm from '@/components/pages/master-data/nonstock/form/NonstockForm';
|
||||||
|
|
||||||
|
import { getNonstock } from '@/services/api/master-data/nonstock';
|
||||||
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
|
||||||
|
const NonstockEdit = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const nonstockId = searchParams.get('nonstockId');
|
||||||
|
|
||||||
|
const { data: nonstock, isLoading: isLoadingNonstock } = useSWR(
|
||||||
|
nonstockId,
|
||||||
|
getNonstock
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!nonstockId) {
|
||||||
|
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 (!isLoadingNonstock && !nonstock) {
|
||||||
|
router.replace('/404');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full p-4 flex flex-row justify-center'>
|
||||||
|
{isLoadingNonstock && (
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
)}
|
||||||
|
{!isLoadingNonstock && isResponseSuccess(nonstock) && (
|
||||||
|
<NonstockForm type='edit' initialValues={nonstock.data} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default NonstockEdit;
|
||||||
Reference in New Issue
Block a user