refactor(FE-438): Add icon position/size and subtitle to modal

This commit is contained in:
rstubryan
2025-12-28 16:44:01 +07:00
parent c0a818af7e
commit b1ccad081d
2 changed files with 238 additions and 40 deletions
+79 -6
View File
@@ -8,10 +8,13 @@ import Button, { ButtonProps } from '@/components/Button';
import { cn } from '@/lib/helper'; import { cn } from '@/lib/helper';
export type IconPosition = 'left' | 'center' | 'right';
export interface ConfirmationModalProps { export interface ConfirmationModalProps {
ref: RefObject<HTMLDialogElement | null>; ref: RefObject<HTMLDialogElement | null>;
type?: 'info' | 'success' | 'error'; type?: 'info' | 'success' | 'error';
text?: string; text?: string;
subtitleText?: string;
closeOnBackdrop?: boolean; closeOnBackdrop?: boolean;
primaryButton?: ButtonProps & { primaryButton?: ButtonProps & {
text?: string; text?: string;
@@ -24,17 +27,22 @@ export interface ConfirmationModalProps {
modalBox?: string; modalBox?: string;
}; };
children?: React.ReactNode; children?: React.ReactNode;
iconSize?: number;
iconPosition?: IconPosition;
} }
const ConfirmationModal = ({ const ConfirmationModal = ({
ref, ref,
type = 'info', type = 'info',
text, text,
subtitleText,
closeOnBackdrop, closeOnBackdrop,
primaryButton, primaryButton,
secondaryButton, secondaryButton,
className, className,
children, children,
iconSize = 64,
iconPosition = 'center',
}: ConfirmationModalProps) => { }: ConfirmationModalProps) => {
const [isPrimaryButtonLoading, setIsPrimaryButtonLoading] = useState(false); const [isPrimaryButtonLoading, setIsPrimaryButtonLoading] = useState(false);
@@ -55,6 +63,8 @@ const ConfirmationModal = ({
return ( return (
<Modal ref={ref} closeOnBackdrop={closeOnBackdrop} className={className}> <Modal ref={ref} closeOnBackdrop={closeOnBackdrop} className={className}>
<div className='w-full flex flex-col gap-4'> <div className='w-full flex flex-col gap-4'>
{iconPosition === 'center' ? (
<>
<div <div
className={cn( className={cn(
'w-fit p-4 mx-auto flex flex-row justify-center items-center rounded-full', 'w-fit p-4 mx-auto flex flex-row justify-center items-center rounded-full',
@@ -68,8 +78,8 @@ const ConfirmationModal = ({
{type === 'info' && ( {type === 'info' && (
<Icon <Icon
icon='material-symbols:info-outline-rounded' icon='material-symbols:info-outline-rounded'
width={64} width={iconSize}
height={64} height={iconSize}
className='text-info-content' className='text-info-content'
/> />
)} )}
@@ -77,8 +87,8 @@ const ConfirmationModal = ({
{type === 'success' && ( {type === 'success' && (
<Icon <Icon
icon='qlementine-icons:success-12' icon='qlementine-icons:success-12'
width={64} width={iconSize}
height={64} height={iconSize}
className='text-success-content' className='text-success-content'
/> />
)} )}
@@ -86,8 +96,8 @@ const ConfirmationModal = ({
{type === 'error' && ( {type === 'error' && (
<Icon <Icon
icon='solar:danger-triangle-linear' icon='solar:danger-triangle-linear'
width={64} width={iconSize}
height={64} height={iconSize}
className='text-error-content' className='text-error-content'
/> />
)} )}
@@ -97,6 +107,69 @@ const ConfirmationModal = ({
{text ?? 'Apakah anda yakin ingin melakukan hal ini?'} {text ?? 'Apakah anda yakin ingin melakukan hal ini?'}
</p> </p>
{subtitleText && (
<p className='text-center text-sm text-gray-400'>
{subtitleText}
</p>
)}
</>
) : (
<div
className={cn('flex flex-row items-center gap-4', {
'flex-row': iconPosition === 'left',
'flex-row-reverse': iconPosition === 'right',
})}
>
<div
className={cn(
'w-fit p-4 flex flex-row justify-center items-center rounded-full',
{
'bg-error': type === 'error',
'bg-info': type === 'info',
'bg-success': type === 'success',
}
)}
>
{type === 'info' && (
<Icon
icon='material-symbols:info-outline-rounded'
width={iconSize}
height={iconSize}
className='text-info-content'
/>
)}
{type === 'success' && (
<Icon
icon='qlementine-icons:success-12'
width={iconSize}
height={iconSize}
className='text-success-content'
/>
)}
{type === 'error' && (
<Icon
icon='solar:danger-triangle-linear'
width={iconSize}
height={iconSize}
className='text-error-content'
/>
)}
</div>
<div className='flex flex-col gap-1'>
<p className='font-medium'>
{text ?? 'Apakah anda yakin ingin melakukan hal ini?'}
</p>
{subtitleText && (
<p className='text-sm text-gray-400'>{subtitleText}</p>
)}
</div>
</div>
)}
{children && <div className='w-full'>{children}</div>} {children && <div className='w-full'>{children}</div>}
<div className='w-full flex flex-row gap-2'> <div className='w-full flex flex-row gap-2'>
@@ -420,6 +420,8 @@ const UniformityTable = ({ refresh }: { refresh?: () => void }) => {
<ConfirmationModal <ConfirmationModal
ref={singleDeleteModal.ref} ref={singleDeleteModal.ref}
type='error' type='error'
iconPosition='left'
iconSize={32}
text={`Apakah anda yakin ingin menghapus data Uniformity ini?`} text={`Apakah anda yakin ingin menghapus data Uniformity ini?`}
secondaryButton={{ secondaryButton={{
text: 'Tidak', text: 'Tidak',
@@ -430,11 +432,71 @@ const UniformityTable = ({ refresh }: { refresh?: () => void }) => {
isLoading: isDeleteLoading, isLoading: isDeleteLoading,
onClick: singleDeleteHandler, onClick: singleDeleteHandler,
}} }}
className={{
modalBox: 'rounded-2xl',
}}
>
{' '}
<div className='flex flex-col gap-4 mt-4'>
<Table
data={[
{
id: 'tanggal',
label: 'Tanggal',
value: '28 Desember 2025',
},
{
id: 'lokasi-farm',
label: 'Lokasi Farm',
value: 'Farm A',
},
{
id: 'project-flock',
label: 'Project Flock',
value: 'Flock 2025-01',
},
{
id: 'kandang',
label: 'Kandang',
value: 'Kandang 1',
},
{
id: 'file-uniformity',
label: 'File Uniformity',
value: 'uniformity_data.xlsx',
},
{
id: 'status',
label: 'Status',
value: 'Disetujui',
},
]}
columns={[
{
accessorKey: 'label',
header: 'Label',
cell: (props) => props.row.original.label,
},
{
accessorKey: 'value',
header: 'Value',
cell: (props) => <span>{props.row.original.value}</span>,
},
]}
pageSize={6}
className={{
containerClassName: 'mb-0',
paginationClassName: 'hidden',
}}
/> />
</div>
</ConfirmationModal>
<ConfirmationModal <ConfirmationModal
ref={bulkDeleteModal.ref} ref={bulkDeleteModal.ref}
type='error' type='error'
iconPosition='left'
iconSize={32}
text={`Apakah anda yakin ingin menghapus ${selectedRowIds.length} data Uniformity yang dipilih?`} text={`Apakah anda yakin ingin menghapus ${selectedRowIds.length} data Uniformity yang dipilih?`}
secondaryButton={{ secondaryButton={{
text: 'Tidak', text: 'Tidak',
@@ -445,18 +507,81 @@ const UniformityTable = ({ refresh }: { refresh?: () => void }) => {
isLoading: isBulkActionLoading, isLoading: isBulkActionLoading,
onClick: bulkDeleteHandler, onClick: bulkDeleteHandler,
}} }}
className={{
modalBox: 'rounded-2xl',
}}
>
<div className='flex flex-col gap-4 mt-4'>
<Table
data={[
{
id: 'tanggal',
label: 'Tanggal',
value: '28 Desember 2025',
},
{
id: 'lokasi-farm',
label: 'Lokasi Farm',
value: 'Farm A',
},
{
id: 'project-flock',
label: 'Project Flock',
value: 'Flock 2025-01',
},
{
id: 'kandang',
label: 'Kandang',
value: 'Kandang 1',
},
{
id: 'file-uniformity',
label: 'File Uniformity',
value: 'uniformity_data.xlsx',
},
{
id: 'status',
label: 'Status',
value: 'Disetujui',
},
]}
columns={[
{
accessorKey: 'label',
header: 'Label',
cell: (props) => props.row.original.label,
},
{
accessorKey: 'value',
header: 'Value',
cell: (props) => <span>{props.row.original.value}</span>,
},
]}
pageSize={6}
className={{
containerClassName: 'mb-0',
paginationClassName: 'hidden',
}}
/> />
</div>
</ConfirmationModal>
<ConfirmationModal <ConfirmationModal
ref={successModal.ref} ref={successModal.ref}
type='success' type='success'
iconPosition='left'
iconSize={32}
text='Data Berhasil Ditambahkan' text='Data Berhasil Ditambahkan'
subtitleText='Data uniformity telah berhasil disimpan.'
closeOnBackdrop={false} closeOnBackdrop={false}
primaryButton={{ primaryButton={{
text: 'Ok', text: 'Ok',
color: 'primary', color: 'primary',
onClick: handleSuccessModalClose, onClick: handleSuccessModalClose,
}} }}
className={{
modalBox: 'rounded-2xl',
}}
> >
<div className='flex flex-col gap-4 mt-4'> <div className='flex flex-col gap-4 mt-4'>
<Table <Table