From 0e43957e6ea2bc9d735a35a792f3430a1808cdf7 Mon Sep 17 00:00:00 2001 From: rstubryan Date: Thu, 29 Jan 2026 14:58:09 +0700 Subject: [PATCH] refactor(FE): Replace Badge with StatusBadge in uniformity views --- .../production/uniformity/UniformityTable.tsx | 800 +++++++++--------- .../detail/UniformityDetailsPreview.tsx | 33 +- .../uniformity/form/UniformityResultForm.tsx | 33 +- 3 files changed, 406 insertions(+), 460 deletions(-) diff --git a/src/components/pages/production/uniformity/UniformityTable.tsx b/src/components/pages/production/uniformity/UniformityTable.tsx index be133c7c..6cf28f02 100644 --- a/src/components/pages/production/uniformity/UniformityTable.tsx +++ b/src/components/pages/production/uniformity/UniformityTable.tsx @@ -19,6 +19,7 @@ import { isResponseSuccess } from '@/lib/api-helper'; import { type BaseApiResponse } from '@/types/api/api-general'; import Table from '@/components/Table'; import Badge from '@/components/Badge'; +import StatusBadge from '@/components/helper/StatusBadge'; import CheckboxInput from '@/components/input/CheckboxInput'; import { useModal } from '@/components/Modal'; import ConfirmationModal from '@/components/modal/ConfirmationModal'; @@ -45,6 +46,7 @@ import { getStatusColor, getStatusIndicatorColor, getStatusText, + getStatusBadgeColor, } from '@/components/pages/production/uniformity/uniformity-utils'; import { generateUniformityPDF } from '@/components/pages/production/uniformity/export/UniformityExportPDF'; import { generateUniformityExcel } from '@/components/pages/production/uniformity/export/UniformityExportExcel'; @@ -832,7 +834,7 @@ const UniformityTable = () => { }, cell: ({ row }) => { return ( -
+
{ { accessorKey: 'week', header: 'Tanggal (Week)', - cell: (props) => - `${formatDate(props.row.original.applied_at, 'DD MMM YYYY')} (${props.row.original.week})`, + cell: (props) => ( + + {`${formatDate(props.row.original.applied_at, 'DD MMM YYYY')} (${props.row.original.week})`} + + ), }, { accessorKey: 'status', @@ -872,20 +877,11 @@ const UniformityTable = () => { const uniformity = props.row.original; const status = uniformity.latest_approval?.action ?? uniformity.status; - return ( -
- - {getStatusText(status)} - -
- ); + + const badgeColor = getStatusBadgeColor(status); + const statusText = getStatusText(status); + + return ; }, }, { @@ -1039,425 +1035,413 @@ const UniformityTable = () => {
-
- - data={isResponseSuccess(uniformities) ? uniformities?.data : []} - columns={uniformityColumns} - pageSize={tableFilterState.pageSize} - page={isResponseSuccess(uniformities) ? uniformities?.meta?.page : 0} - totalItems={ - isResponseSuccess(uniformities) - ? uniformities?.meta?.total_results - : 0 - } - onPageChange={setPage} - isLoading={isLoading} - sorting={sorting} - setSorting={setSorting} - rowSelection={rowSelection} - setRowSelection={setRowSelection} - className={{ - containerClassName: cn({ - 'mb-20': - isResponseSuccess(uniformities) && - uniformities?.data?.length === 0, - }), - tableWrapperClassName: 'overflow-x-auto min-h-full rounded-xl', - tableClassName: 'font-inter w-full table-auto min-h-full!', - headerRowClassName: 'border-b border-b-gray-200', - headerColumnClassName: - 'px-6 py-3 text-xs font-semibold text-gray-500 last:flex last:flex-row last:justify-end', - bodyRowClassName: 'border-b border-b-gray-200', - bodyColumnClassName: - 'px-6 py-3 last:flex last:flex-row last:justify-end', - }} - emptyContent={} - /> + + data={isResponseSuccess(uniformities) ? uniformities?.data : []} + columns={uniformityColumns} + pageSize={tableFilterState.pageSize} + page={isResponseSuccess(uniformities) ? uniformities?.meta?.page : 0} + totalItems={ + isResponseSuccess(uniformities) + ? uniformities?.meta?.total_results + : 0 + } + onPageChange={setPage} + isLoading={isLoading} + sorting={sorting} + setSorting={setSorting} + rowSelection={rowSelection} + setRowSelection={setRowSelection} + className={{ + containerClassName: cn('p-3 pt-0', { + 'mb-20': + isResponseSuccess(uniformities) && + uniformities?.data?.length === 0, + }), + headerColumnClassName: 'text-nowrap', + }} + emptyContent={} + /> - -
- {createdUniformity ? ( - - ) : selectedRowIds.length === 1 ? ( - - ) : ( -
- {selectedRowIds.length} data dipilih -
- )} -
-
- - -
- -
-
- - -
- {selectedRowIds.length === 1 ? ( - - ) : ( -
- {selectedRowIds.length} data dipilih -
- )} -
-
- - -
- -
-
- - -
- {selectedRowIds.length === 1 ? ( - - ) : ( -
- {selectedRowIds.length} data dipilih -
- )} -
-
- - -
- {selectedRowIds.length === 1 ? ( - - ) : ( -
- {selectedRowIds.length} data dipilih -
- )} -
-
- - {/* Filter Modal */} - -
- {/* Modal Header */} -
-
- -

Filter Data

-
- + +
+ {createdUniformity ? ( + + ) : selectedRowIds.length === 1 ? ( + + ) : ( +
+ {selectedRowIds.length} data dipilih
+ )} +
+
-
-
-
- -
+ +
+ +
+
-
- -
-
+ +
+ {selectedRowIds.length === 1 ? ( + + ) : ( +
+ {selectedRowIds.length} data dipilih +
+ )} +
+
+ +
+ +
+
+ + +
+ {selectedRowIds.length === 1 ? ( + + ) : ( +
+ {selectedRowIds.length} data dipilih +
+ )} +
+
+ + +
+ {selectedRowIds.length === 1 ? ( + + ) : ( +
+ {selectedRowIds.length} data dipilih +
+ )} +
+
+ + {/* Filter Modal */} + +
+ {/* Modal Header */} +
+
+ +

Filter Data

+
+ +
+ +
+
- { - handleFilterLocationChange(value); - }} - options={filterLocationOptions} - onInputChange={setFilterLocationInputValue} - isLoading={isLoadingFilterLocations} - onMenuScrollToBottom={loadMoreFilterLocations} + label='Tanggal mulai' + name='start_date' + value={filterFormik.values.start_date} + onChange={handleFilterStartDateChange} + onBlur={filterFormik.handleBlur} isError={ - filterFormik.touched.location && - Boolean(filterFormik.errors.location) + filterFormik.touched.start_date && + Boolean(filterFormik.errors.start_date) } - errorMessage={filterFormik.errors.location} - isClearable + errorMessage={filterFormik.errors.start_date} className={{ wrapper: 'w-full' }} />
- { - handleFilterProjectFlockChange(value); - }} - options={filterProjectFlockOptions} - onInputChange={setFilterProjectFlockSearchValue} - isLoading={isLoadingFilterProjectFlocks} - onMenuScrollToBottom={loadMoreFilterProjectFlocks} - isDisabled={!filterFormik.values.location} + label='Tanggal akhir' + name='end_date' + value={filterFormik.values.end_date} + onChange={handleFilterEndDateChange} + onBlur={filterFormik.handleBlur} isError={ - filterFormik.touched.project_flock && - Boolean(filterFormik.errors.project_flock) + filterFormik.touched.end_date && + Boolean(filterFormik.errors.end_date) } - errorMessage={filterFormik.errors.project_flock} - isClearable - className={{ wrapper: 'w-full' }} - /> -
- -
- { - handleFilterKandangChange(value); - }} - options={filterKandangOptions} - isDisabled={!filterFormik.values.project_flock} - isError={ - filterFormik.touched.kandang && - Boolean(filterFormik.errors.kandang) - } - errorMessage={filterFormik.errors.kandang} - isClearable + errorMessage={filterFormik.errors.end_date} className={{ wrapper: 'w-full' }} />
-
- {/* Error List Alert */} - {formErrorList.length > 0 && ( -
- -
- )} +
+ { + handleFilterLocationChange(value); + }} + options={filterLocationOptions} + onInputChange={setFilterLocationInputValue} + isLoading={isLoadingFilterLocations} + onMenuScrollToBottom={loadMoreFilterLocations} + isError={ + filterFormik.touched.location && + Boolean(filterFormik.errors.location) + } + errorMessage={filterFormik.errors.location} + isClearable + className={{ wrapper: 'w-full' }} + />
- {/* Action Buttons */} -
- - +
+ { + handleFilterProjectFlockChange(value); + }} + options={filterProjectFlockOptions} + onInputChange={setFilterProjectFlockSearchValue} + isLoading={isLoadingFilterProjectFlocks} + onMenuScrollToBottom={loadMoreFilterProjectFlocks} + isDisabled={!filterFormik.values.location} + isError={ + filterFormik.touched.project_flock && + Boolean(filterFormik.errors.project_flock) + } + errorMessage={filterFormik.errors.project_flock} + isClearable + className={{ wrapper: 'w-full' }} + /> +
+ +
+ { + handleFilterKandangChange(value); + }} + options={filterKandangOptions} + isDisabled={!filterFormik.values.project_flock} + isError={ + filterFormik.touched.kandang && + Boolean(filterFormik.errors.kandang) + } + errorMessage={filterFormik.errors.kandang} + isClearable + className={{ wrapper: 'w-full' }} + />
- - {/* Floating Actions Button */} - + {/* Error List Alert */} + {formErrorList.length > 0 && ( +
+ +
+ )} +
+ + {/* Action Buttons */} +
+ + +
+
+ + + {/* Floating Actions Button */} + -
+ permissions: 'lti.production.uniformity.detail', + }, + { + action: 'DELETE', + icon: 'mdi:delete-outline', + label: 'Delete', + hidden: selectedRowIds.length !== 1, + onClick: handleDelete, + permissions: 'lti.production.uniformity.delete', + }, + ]} + approvals={[ + { + action: 'APPROVED', + icon: 'mdi:check-circle-outline', + label: 'Approve', + onClick: handleBulkApprove, + permissions: 'lti.production.uniformity.approve', + disabled: !canApproveReject, + }, + { + action: 'REJECTED', + icon: 'mdi:close-circle-outline', + label: 'Reject', + onClick: handleBulkReject, + permissions: 'lti.production.uniformity.approve', + disabled: !canApproveReject, + }, + ]} + selectedRowIds={selectedRowIds} + onClose={handleCloseFab} + /> ); }; diff --git a/src/components/pages/production/uniformity/detail/UniformityDetailsPreview.tsx b/src/components/pages/production/uniformity/detail/UniformityDetailsPreview.tsx index 9188ba59..8d38d669 100644 --- a/src/components/pages/production/uniformity/detail/UniformityDetailsPreview.tsx +++ b/src/components/pages/production/uniformity/detail/UniformityDetailsPreview.tsx @@ -10,11 +10,10 @@ import { UniformityInfoUmum, } from '@/types/api/production/uniformity'; import Table from '@/components/Table'; -import Badge from '@/components/Badge'; +import StatusBadge from '@/components/helper/StatusBadge'; import { - getWeightStatusColor, - getWeightStatusIndicatorColor, getWeightStatusText, + getWeightStatusBadgeColor, } from '@/components/pages/production/uniformity/uniformity-utils'; import { BodyWeightData } from '@/types/api/production/uniformity'; @@ -65,30 +64,12 @@ const UniformityDetailsPreview = ({ cell: (props) => { const status = props.row.original.status; return status ? ( -
- - {getWeightStatusText(status)} - -
+ ) : ( - - Unknown - + ); }, }, diff --git a/src/components/pages/production/uniformity/form/UniformityResultForm.tsx b/src/components/pages/production/uniformity/form/UniformityResultForm.tsx index 103fc791..5963df8a 100644 --- a/src/components/pages/production/uniformity/form/UniformityResultForm.tsx +++ b/src/components/pages/production/uniformity/form/UniformityResultForm.tsx @@ -14,12 +14,11 @@ import { useRouter } from 'next/navigation'; import toast from 'react-hot-toast'; import { UniformityApi } from '@/services/api/uniformity'; import { isResponseError } from '@/lib/api-helper'; -import Badge from '@/components/Badge'; +import StatusBadge from '@/components/helper/StatusBadge'; import { formatNumber } from '@/lib/helper'; import { - getWeightStatusColor, - getWeightStatusIndicatorColor, getWeightStatusText, + getWeightStatusBadgeColor, } from '@/components/pages/production/uniformity/uniformity-utils'; import { DetailOptionType } from '@/types/api/production/uniformity'; import { @@ -204,30 +203,12 @@ const UniformityResultForm = () => { cell: (props) => { const status = props.row.original.status; return status ? ( -
- - {getWeightStatusText(status)} - -
+ ) : ( - - Unknown - + ); }, },