mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-26 00:05:45 +00:00
feat: use TransferToLayingConfirmationModal and remove unnecessary code
This commit is contained in:
@@ -14,9 +14,7 @@ import { Icon } from '@iconify/react';
|
|||||||
import Table from '@/components/Table';
|
import Table from '@/components/Table';
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import { useModal } from '@/components/Modal';
|
import { useModal } from '@/components/Modal';
|
||||||
import ConfirmationModal from '@/components/modal/ConfirmationModal';
|
|
||||||
import CheckboxInput from '@/components/input/CheckboxInput';
|
import CheckboxInput from '@/components/input/CheckboxInput';
|
||||||
import ConfirmationModalWithNotes from '@/components/modal/ConfirmationModalWithNotes';
|
|
||||||
import RequirePermission from '@/components/helper/RequirePermission';
|
import RequirePermission from '@/components/helper/RequirePermission';
|
||||||
import PopoverButton from '@/components/popover/PopoverButton';
|
import PopoverButton from '@/components/popover/PopoverButton';
|
||||||
import Badge from '@/components/Badge';
|
import Badge from '@/components/Badge';
|
||||||
@@ -24,13 +22,14 @@ import PopoverContent from '@/components/popover/PopoverContent';
|
|||||||
import Dropdown from '@/components/Dropdown';
|
import Dropdown from '@/components/Dropdown';
|
||||||
import StatusBadge from '@/components/helper/StatusBadge';
|
import StatusBadge from '@/components/helper/StatusBadge';
|
||||||
import TransferToLayingFilterModal from '@/components/pages/production/transfer-to-laying/TransferToLayingFilterModal';
|
import TransferToLayingFilterModal from '@/components/pages/production/transfer-to-laying/TransferToLayingFilterModal';
|
||||||
|
import TransferToLayingConfirmationModal from '@/components/pages/production/transfer-to-laying/TransferToLayingConfirmationModal';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
TransferToLaying,
|
TransferToLaying,
|
||||||
TransferToLayingFilter,
|
TransferToLayingFilter,
|
||||||
} from '@/types/api/production/transfer-to-laying';
|
} from '@/types/api/production/transfer-to-laying';
|
||||||
import { TransferToLayingApi } from '@/services/api/production/transfer-to-laying';
|
import { TransferToLayingApi } from '@/services/api/production/transfer-to-laying';
|
||||||
import { cn, formatDate } from '@/lib/helper';
|
import { cn, formatDate, formatNumber } from '@/lib/helper';
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
||||||
import { Color } from '@/types/theme';
|
import { Color } from '@/types/theme';
|
||||||
@@ -38,14 +37,11 @@ import { Color } from '@/types/theme';
|
|||||||
const RowOptionsMenu = ({
|
const RowOptionsMenu = ({
|
||||||
props,
|
props,
|
||||||
popoverPosition = 'bottom',
|
popoverPosition = 'bottom',
|
||||||
approveClickHandler,
|
|
||||||
rejectClickHandler,
|
|
||||||
deleteClickHandler,
|
deleteClickHandler,
|
||||||
}: {
|
}: {
|
||||||
props: CellContext<TransferToLaying, unknown>;
|
props: CellContext<TransferToLaying, unknown>;
|
||||||
popoverPosition: 'bottom' | 'top';
|
popoverPosition: 'bottom' | 'top';
|
||||||
approveClickHandler: () => void;
|
|
||||||
rejectClickHandler: () => void;
|
|
||||||
deleteClickHandler: () => void;
|
deleteClickHandler: () => void;
|
||||||
}) => {
|
}) => {
|
||||||
const showEditButton =
|
const showEditButton =
|
||||||
@@ -54,9 +50,6 @@ const RowOptionsMenu = ({
|
|||||||
|
|
||||||
const showDeleteButton = showEditButton;
|
const showDeleteButton = showEditButton;
|
||||||
|
|
||||||
// const showApproveButton = showEditButton;
|
|
||||||
// const showRejectButton = showEditButton;
|
|
||||||
|
|
||||||
const popoverId = `transferToLaying#${props.row.original.id}`;
|
const popoverId = `transferToLaying#${props.row.original.id}`;
|
||||||
const popoverAnchorName = `--anchor-transferToLaying#${props.row.original.id}`;
|
const popoverAnchorName = `--anchor-transferToLaying#${props.row.original.id}`;
|
||||||
|
|
||||||
@@ -260,7 +253,14 @@ const TransferToLayingsTable = () => {
|
|||||||
{
|
{
|
||||||
accessorKey: 'usage_qty',
|
accessorKey: 'usage_qty',
|
||||||
header: 'Kuantitas',
|
header: 'Kuantitas',
|
||||||
cell: (props) => props.getValue() ?? props.row.original.pending_usage_qty,
|
cell: (props) => {
|
||||||
|
const totalQuantity = props.row.original.targets.reduce(
|
||||||
|
(total, target) => total + target.qty,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
return formatNumber(totalQuantity, 'en-US');
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
accessorKey: 'notes',
|
accessorKey: 'notes',
|
||||||
@@ -304,38 +304,20 @@ const TransferToLayingsTable = () => {
|
|||||||
|
|
||||||
const isLast2Rows = currentRowRelativeIndex > currentPageSize - 2;
|
const isLast2Rows = currentRowRelativeIndex > currentPageSize - 2;
|
||||||
|
|
||||||
const approveClickHandler = () => {
|
|
||||||
setSelectedTransferToLaying(props.row.original);
|
|
||||||
|
|
||||||
// Set row selection
|
|
||||||
setRowSelection({
|
|
||||||
[String(props.row.original.id)]: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
approveModal.openModal();
|
|
||||||
};
|
|
||||||
|
|
||||||
const rejectClickHandler = () => {
|
|
||||||
setSelectedTransferToLaying(props.row.original);
|
|
||||||
|
|
||||||
// Set row selection
|
|
||||||
setRowSelection({
|
|
||||||
[String(props.row.original.id)]: true,
|
|
||||||
});
|
|
||||||
|
|
||||||
rejectModal.openModal();
|
|
||||||
};
|
|
||||||
|
|
||||||
const deleteClickHandler = () => {
|
const deleteClickHandler = () => {
|
||||||
setSelectedTransferToLaying(props.row.original);
|
setSelectedTransferToLaying(props.row.original);
|
||||||
|
|
||||||
|
// Set row selection
|
||||||
|
setRowSelection({
|
||||||
|
[String(props.row.original.id)]: true,
|
||||||
|
});
|
||||||
|
|
||||||
deleteModal.openModal();
|
deleteModal.openModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<RowOptionsMenu
|
<RowOptionsMenu
|
||||||
props={props}
|
props={props}
|
||||||
approveClickHandler={approveClickHandler}
|
|
||||||
rejectClickHandler={rejectClickHandler}
|
|
||||||
deleteClickHandler={deleteClickHandler}
|
deleteClickHandler={deleteClickHandler}
|
||||||
popoverPosition={isLast2Rows ? 'top' : 'bottom'}
|
popoverPosition={isLast2Rows ? 'top' : 'bottom'}
|
||||||
/>
|
/>
|
||||||
@@ -377,6 +359,8 @@ const TransferToLayingsTable = () => {
|
|||||||
|
|
||||||
refreshTransferToLayings();
|
refreshTransferToLayings();
|
||||||
|
|
||||||
|
setRowSelection({});
|
||||||
|
setSelectedTransferToLaying(undefined);
|
||||||
deleteModal.closeModal();
|
deleteModal.closeModal();
|
||||||
toast.success('Berhasil menghapus data transfer ke laying!');
|
toast.success('Berhasil menghapus data transfer ke laying!');
|
||||||
setIsDeleteLoading(false);
|
setIsDeleteLoading(false);
|
||||||
@@ -646,53 +630,70 @@ const TransferToLayingsTable = () => {
|
|||||||
onReset={filterResetHandler}
|
onReset={filterResetHandler}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ConfirmationModal
|
<TransferToLayingConfirmationModal
|
||||||
ref={deleteModal.ref}
|
ref={deleteModal.ref}
|
||||||
iconPosition='left'
|
|
||||||
type='error'
|
type='error'
|
||||||
text='Delete This Data?'
|
text='Delete This Data?'
|
||||||
subtitleText='Are you sure you want to delete this data? '
|
subtitleText='Are you sure you want to delete this data? '
|
||||||
|
transferToLayingIds={selectedRowIds}
|
||||||
|
primaryButton={{
|
||||||
|
isLoading: isDeleteLoading,
|
||||||
|
color: 'error',
|
||||||
|
onClick: confirmationModalDeleteClickHandler,
|
||||||
|
}}
|
||||||
secondaryButton={{
|
secondaryButton={{
|
||||||
text: 'Cancel',
|
text: 'Cancel',
|
||||||
}}
|
color: 'none',
|
||||||
primaryButton={{
|
onClick: () => {
|
||||||
text: 'Delete',
|
setRowSelection({});
|
||||||
color: 'error',
|
deleteModal.closeModal();
|
||||||
isLoading: isDeleteLoading,
|
},
|
||||||
onClick: confirmationModalDeleteClickHandler,
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ConfirmationModalWithNotes
|
{/* Approve Modal */}
|
||||||
|
<TransferToLayingConfirmationModal
|
||||||
ref={approveModal.ref}
|
ref={approveModal.ref}
|
||||||
type='success'
|
|
||||||
iconPosition='left'
|
|
||||||
text='Approve This Submission?'
|
text='Approve This Submission?'
|
||||||
subtitleText='Are you sure you want to approve this submission?'
|
subtitleText='Are you sure you want to approve this submission?'
|
||||||
secondaryButton={{
|
type='success'
|
||||||
text: 'Cancel',
|
transferToLayingIds={selectedRowIds}
|
||||||
}}
|
withNote
|
||||||
|
noteLabel='Notes Approval'
|
||||||
primaryButton={{
|
primaryButton={{
|
||||||
text: 'Approve',
|
|
||||||
color: 'success',
|
|
||||||
isLoading: isApproveLoading,
|
isLoading: isApproveLoading,
|
||||||
onClick: confirmationModalApproveClickHandler,
|
onClick: confirmationModalApproveClickHandler,
|
||||||
}}
|
}}
|
||||||
/>
|
|
||||||
|
|
||||||
<ConfirmationModalWithNotes
|
|
||||||
ref={rejectModal.ref}
|
|
||||||
type='error'
|
|
||||||
iconPosition='left'
|
|
||||||
text='Reject This Submission?'
|
|
||||||
subtitleText='Are you sure you want to reject this submission?'
|
|
||||||
secondaryButton={{
|
secondaryButton={{
|
||||||
text: 'Cancel',
|
text: 'Cancel',
|
||||||
|
color: 'none',
|
||||||
|
onClick: () => {
|
||||||
|
setRowSelection({});
|
||||||
|
approveModal.closeModal();
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{/* Reject Modal */}
|
||||||
|
<TransferToLayingConfirmationModal
|
||||||
|
ref={rejectModal.ref}
|
||||||
|
type='error'
|
||||||
|
text='Reject This Submission?'
|
||||||
|
subtitleText='Are you sure you want to reject this submission?'
|
||||||
|
transferToLayingIds={selectedRowIds}
|
||||||
|
withNote
|
||||||
|
noteLabel='Notes Reject'
|
||||||
|
secondaryButton={{
|
||||||
|
text: 'Cancel',
|
||||||
|
color: 'none',
|
||||||
|
onClick: () => {
|
||||||
|
setRowSelection({});
|
||||||
|
rejectModal.closeModal();
|
||||||
|
},
|
||||||
}}
|
}}
|
||||||
primaryButton={{
|
primaryButton={{
|
||||||
text: 'Reject',
|
|
||||||
color: 'error',
|
|
||||||
isLoading: isRejectLoading,
|
isLoading: isRejectLoading,
|
||||||
|
color: 'error',
|
||||||
onClick: confirmationModalRejectClickHandler,
|
onClick: confirmationModalRejectClickHandler,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user