mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-24 23:35:45 +00:00
refactor(FE-438): Add icon position/size and subtitle to modal
This commit is contained in:
@@ -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,47 +63,112 @@ 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'>
|
||||||
<div
|
{iconPosition === 'center' ? (
|
||||||
className={cn(
|
<>
|
||||||
'w-fit p-4 mx-auto flex flex-row justify-center items-center rounded-full',
|
<div
|
||||||
{
|
className={cn(
|
||||||
'bg-error': type === 'error',
|
'w-fit p-4 mx-auto flex flex-row justify-center items-center rounded-full',
|
||||||
'bg-info': type === 'info',
|
{
|
||||||
'bg-success': type === 'success',
|
'bg-error': type === 'error',
|
||||||
}
|
'bg-info': type === 'info',
|
||||||
)}
|
'bg-success': type === 'success',
|
||||||
>
|
}
|
||||||
{type === 'info' && (
|
)}
|
||||||
<Icon
|
>
|
||||||
icon='material-symbols:info-outline-rounded'
|
{type === 'info' && (
|
||||||
width={64}
|
<Icon
|
||||||
height={64}
|
icon='material-symbols:info-outline-rounded'
|
||||||
className='text-info-content'
|
width={iconSize}
|
||||||
/>
|
height={iconSize}
|
||||||
)}
|
className='text-info-content'
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
{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'
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{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'
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<p className='text-center font-medium'>
|
<p className='text-center font-medium'>
|
||||||
{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>}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user