diff --git a/src/app/master-data/nonstock/detail/edit/page.tsx b/src/app/master-data/nonstock/detail/edit/page.tsx new file mode 100644 index 00000000..a0fbb6b3 --- /dev/null +++ b/src/app/master-data/nonstock/detail/edit/page.tsx @@ -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 ( +
+ +
+ ); + } + + if (!isLoadingNonstock && !nonstock) { + router.replace('/404'); + return; + } + + return ( +
+ {isLoadingNonstock && ( + + )} + {!isLoadingNonstock && isResponseSuccess(nonstock) && ( + + )} +
+ ); +}; + +export default NonstockEdit;