Merge branch 'hot-fix/master-data-flock' into 'development'

[FIX/FE] Show server error message

See merge request mbugroup/lti-web-client!199
This commit is contained in:
Rivaldi A N S
2026-01-17 04:15:14 +00:00
2 changed files with 64 additions and 32 deletions
@@ -33,22 +33,6 @@ const RowsOptions = ({
}) => { }) => {
return ( return (
<RowOptionsMenuWrapper type={type}> <RowOptionsMenuWrapper type={type}>
<RequirePermission permissions='lti.master.flocks.update'>
<Button
href={`/master-data/flock/detail/edit/?flockId=${props.row.original.id}`}
variant='ghost'
color='warning'
className='justify-start text-sm'
>
<Icon
icon='material-symbols:edit-outline'
width={16}
height={16}
className='justify-start text-sm'
/>
Edit
</Button>
</RequirePermission>
<RequirePermission permissions='lti.master.flocks.detail'> <RequirePermission permissions='lti.master.flocks.detail'>
<Button <Button
href={`/master-data/flock/detail/?flockId=${props.row.original.id}`} href={`/master-data/flock/detail/?flockId=${props.row.original.id}`}
@@ -65,6 +49,22 @@ const RowsOptions = ({
Detail Detail
</Button> </Button>
</RequirePermission> </RequirePermission>
<RequirePermission permissions='lti.master.flocks.update'>
<Button
href={`/master-data/flock/detail/edit/?flockId=${props.row.original.id}`}
variant='ghost'
color='warning'
className='justify-start text-sm'
>
<Icon
icon='material-symbols:edit-outline'
width={16}
height={16}
className='justify-start text-sm'
/>
Edit
</Button>
</RequirePermission>
<RequirePermission permissions='lti.master.flocks.delete'> <RequirePermission permissions='lti.master.flocks.delete'>
<Button <Button
onClick={deleteClickHandler} onClick={deleteClickHandler}
@@ -19,6 +19,8 @@ import ConfirmationModal from '@/components/modal/ConfirmationModal';
import RequirePermission from '@/components/helper/RequirePermission'; import RequirePermission from '@/components/helper/RequirePermission';
import AlertErrorList from '@/components/helper/form/FormErrors'; import AlertErrorList from '@/components/helper/form/FormErrors';
import { useFormikErrorList } from '@/services/hooks/useFormikErrorList'; import { useFormikErrorList } from '@/services/hooks/useFormikErrorList';
import { toast } from 'react-hot-toast';
import Alert from '@/components/Alert';
interface FlockCustomProps { interface FlockCustomProps {
formType?: 'add' | 'edit' | 'detail'; formType?: 'add' | 'edit' | 'detail';
@@ -37,7 +39,13 @@ const FlockForm = ({ formType = 'add', initialValues }: FlockCustomProps) => {
const confirmationModalDeleteClickHandler = async () => { const confirmationModalDeleteClickHandler = async () => {
setIsDeleteLoading(true); setIsDeleteLoading(true);
await FlockApi.delete(initialValues?.id as number); const deleteFlockRes = await FlockApi.delete(initialValues?.id as number);
if (deleteFlockRes?.status === 'error') {
setFlockFormErrorMessage(deleteFlockRes.message);
return;
}
toast.success(deleteFlockRes?.message as string);
deleteModal.closeModal(); deleteModal.closeModal();
setIsDeleteLoading(false); setIsDeleteLoading(false);
@@ -68,12 +76,29 @@ const FlockForm = ({ formType = 'add', initialValues }: FlockCustomProps) => {
// cek type form yang disubmit // cek type form yang disubmit
switch (formType) { switch (formType) {
case 'add': case 'add': {
await FlockApi.create(payload); const createFlockRes = await FlockApi.create(payload);
if (createFlockRes?.status === 'error') {
setFlockFormErrorMessage(createFlockRes.message);
return;
}
toast.success(createFlockRes?.message as string);
break; break;
case 'edit': }
await FlockApi.update(initialValues?.id as number, payload); case 'edit': {
const updateFlockRes = await FlockApi.update(
initialValues?.id as number,
payload
);
if (updateFlockRes?.status === 'error') {
setFlockFormErrorMessage(updateFlockRes.message);
return;
}
toast.success(updateFlockRes?.message as string);
break; break;
}
default: default:
break; break;
} }
@@ -174,6 +199,24 @@ const FlockForm = ({ formType = 'add', initialValues }: FlockCustomProps) => {
)} )}
<AlertErrorList formErrorList={formErrorList} onClose={close} /> <AlertErrorList formErrorList={formErrorList} onClose={close} />
{flockFormErrorMessage && (
<Alert color='error' className='w-full'>
<Icon
icon='material-symbols:error-outline'
width={24}
height={24}
/>
{flockFormErrorMessage}
<Button
onClick={() => setFlockFormErrorMessage('')}
variant='link'
className='ml-auto p-0 w-fit text-white'
color='none'
>
<Icon icon='material-symbols:close' width={24} height={24} />
</Button>
</Alert>
)}
{formType !== 'detail' && ( {formType !== 'detail' && (
<div <div
@@ -197,17 +240,6 @@ const FlockForm = ({ formType = 'add', initialValues }: FlockCustomProps) => {
</div> </div>
)} )}
</div> </div>
{flockFormErrorMessage && (
<div role='alert' className='alert alert-error'>
<Icon
icon='material-symbols:error-outline'
width={24}
height={24}
/>
<span>{flockFormErrorMessage}</span>
</div>
)}
</form> </form>
</section> </section>