mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-26 00:05:45 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4376eeea85 | |||
| f83474ffbf | |||
| 981755ff68 | |||
| dbbc421ce6 | |||
| cadd5b09ba | |||
| 0ced3f3bac | |||
| 5b368ffb78 | |||
| d1b918bcbf | |||
| e6c4a731b1 | |||
| 3dd3172738 | |||
| fa09e140c0 | |||
| 3951f197e3 |
+27
-47
@@ -2,17 +2,6 @@ stages:
|
|||||||
- build
|
- build
|
||||||
- deploy
|
- deploy
|
||||||
|
|
||||||
# ==========================================================
|
|
||||||
# ✅ Global defaults
|
|
||||||
# ==========================================================
|
|
||||||
default:
|
|
||||||
tags:
|
|
||||||
- server-development-biznet
|
|
||||||
interruptible: true
|
|
||||||
|
|
||||||
# ==========================================================
|
|
||||||
# 🏗️ Build Template
|
|
||||||
# ==========================================================
|
|
||||||
.build_template: &build_template
|
.build_template: &build_template
|
||||||
stage: build
|
stage: build
|
||||||
image: node:20-alpine
|
image: node:20-alpine
|
||||||
@@ -50,9 +39,6 @@ default:
|
|||||||
- out/
|
- out/
|
||||||
expire_in: 1 week
|
expire_in: 1 week
|
||||||
|
|
||||||
# ==========================================================
|
|
||||||
# 🚀 Deploy Template
|
|
||||||
# ==========================================================
|
|
||||||
.deploy_template: &deploy_template
|
.deploy_template: &deploy_template
|
||||||
stage: deploy
|
stage: deploy
|
||||||
image:
|
image:
|
||||||
@@ -87,8 +73,8 @@ default:
|
|||||||
|
|
||||||
if [ "$CI_COMMIT_BRANCH" = "development" ]; then
|
if [ "$CI_COMMIT_BRANCH" = "development" ]; then
|
||||||
ENVIRONMENT_NAME="WEB-LTI-DEV"
|
ENVIRONMENT_NAME="WEB-LTI-DEV"
|
||||||
elif [ "$CI_COMMIT_BRANCH" = "staging" ]; then
|
elif [ "$CI_COMMIT_BRANCH" = "master" ]; then
|
||||||
ENVIRONMENT_NAME="WEB-LTI-STAGING"
|
ENVIRONMENT_NAME="WEB-LTI-PROD"
|
||||||
else
|
else
|
||||||
ENVIRONMENT_NAME="UNKNOWN"
|
ENVIRONMENT_NAME="UNKNOWN"
|
||||||
fi
|
fi
|
||||||
@@ -96,11 +82,11 @@ default:
|
|||||||
if [ "$STATUS" = "success" ]; then
|
if [ "$STATUS" = "success" ]; then
|
||||||
COLOR=3066993
|
COLOR=3066993
|
||||||
TITLE="✅ Deployment ${ENVIRONMENT_NAME} Succeeded"
|
TITLE="✅ Deployment ${ENVIRONMENT_NAME} Succeeded"
|
||||||
DESC="Deployment job on branch \${CI_COMMIT_REF_NAME}\ completed successfully."
|
DESC="Deployment job on branch \`${CI_COMMIT_REF_NAME}\` completed successfully."
|
||||||
else
|
else
|
||||||
COLOR=15158332
|
COLOR=15158332
|
||||||
TITLE="❌ Deployment ${ENVIRONMENT_NAME} Failed"
|
TITLE="❌ Deployment ${ENVIRONMENT_NAME} Failed"
|
||||||
DESC="Deployment job on branch \${CI_COMMIT_REF_NAME}\ encountered issues."
|
DESC="Deployment job on branch \`${CI_COMMIT_REF_NAME}\` encountered issues."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
jq -n \
|
jq -n \
|
||||||
@@ -128,9 +114,7 @@ default:
|
|||||||
|
|
||||||
curl -sS -H "Content-Type: application/json" -d @payload.json "$DISCORD_WEBHOOK_URL"
|
curl -sS -H "Content-Type: application/json" -d @payload.json "$DISCORD_WEBHOOK_URL"
|
||||||
|
|
||||||
# ==========================================================
|
# ====== DEVELOPMENT (Branch development) ======
|
||||||
# ==== DEVELOPMENT (Branch development) ======
|
|
||||||
# ==========================================================
|
|
||||||
build:dev:
|
build:dev:
|
||||||
<<: *build_template
|
<<: *build_template
|
||||||
rules:
|
rules:
|
||||||
@@ -138,6 +122,8 @@ build:dev:
|
|||||||
environment:
|
environment:
|
||||||
name: development
|
name: development
|
||||||
variables:
|
variables:
|
||||||
|
# NEXT_PUBLIC_API_BASE_URL: 'https://dev-api-lti.mbugroup.id'
|
||||||
|
# NEXT_PUBLIC_SSO_LOGIN_URL: 'https://dev-api-sso.mbugroup.id'
|
||||||
NEXT_PUBLIC_LTI_URL: 'https://dev-lti-erp.mbugroup.id'
|
NEXT_PUBLIC_LTI_URL: 'https://dev-lti-erp.mbugroup.id'
|
||||||
NEXT_PUBLIC_SSO_LOGIN_URL: 'https://dev-auth-erp.mbugroup.id'
|
NEXT_PUBLIC_SSO_LOGIN_URL: 'https://dev-auth-erp.mbugroup.id'
|
||||||
NEXT_PUBLIC_API_BASE_URL: 'https://dev-api-lti.mbugroup.id/api'
|
NEXT_PUBLIC_API_BASE_URL: 'https://dev-api-lti.mbugroup.id/api'
|
||||||
@@ -155,31 +141,25 @@ deploy:dev:
|
|||||||
environment:
|
environment:
|
||||||
name: development
|
name: development
|
||||||
url: https://dev-lti-erp.mbugroup.id
|
url: https://dev-lti-erp.mbugroup.id
|
||||||
|
# ====== PRODUCTION ======
|
||||||
|
# build:production:
|
||||||
|
# <<: *build_template
|
||||||
|
# rules:
|
||||||
|
# # pilih salah satu: pakai branch master ATAU pakai tags rilis
|
||||||
|
# - if: '$CI_COMMIT_BRANCH == "master"'
|
||||||
|
# # - if: '$CI_COMMIT_TAG' # kalau mau rilis via tag, uncomment ini dan hapus baris di atas
|
||||||
|
# environment:
|
||||||
|
# name: production
|
||||||
|
|
||||||
# ==========================================================
|
# deploy:production:
|
||||||
# ====== STAGING (Branch staging) ======
|
# <<: *deploy_template
|
||||||
# ==========================================================
|
# needs: ["build:production"]
|
||||||
build:staging:
|
# rules:
|
||||||
<<: *build_template
|
# - if: '$CI_COMMIT_BRANCH == "master"'
|
||||||
rules:
|
# # - if: '$CI_COMMIT_TAG' # selaras dengan rule di build:production
|
||||||
- if: '$CI_COMMIT_BRANCH == "staging"'
|
# variables:
|
||||||
environment:
|
# S3_BUCKET: "lti-erp.mbugroup.id"
|
||||||
name: staging
|
# CLOUDFRONT_DISTRIBUTION_ID: "ddfd"
|
||||||
variables:
|
# environment:
|
||||||
NEXT_PUBLIC_LTI_URL: 'https://stg-lti-erp.mbugroup.id'
|
# name: production
|
||||||
NEXT_PUBLIC_SSO_LOGIN_URL: 'https://stg-auth-erp.mbugroup.id'
|
|
||||||
NEXT_PUBLIC_API_BASE_URL: 'https://stg-api-lti.mbugroup.id/api'
|
|
||||||
NEXT_PUBLIC_CLIENT_ID: 'Lumbung-Telur-Indonesia'
|
|
||||||
|
|
||||||
deploy:staging:
|
|
||||||
<<: *deploy_template
|
|
||||||
needs: ['build:staging']
|
|
||||||
rules:
|
|
||||||
- if: '$CI_COMMIT_BRANCH == "staging"'
|
|
||||||
variables:
|
|
||||||
S3_BUCKET: 'stg-lti-erp.mbugroup.id'
|
|
||||||
AWS_REGION: 'ap-southeast-3'
|
|
||||||
CLOUDFRONT_DISTRIBUTION_ID: 'E2V6PPO1AUIU7H'
|
|
||||||
environment:
|
|
||||||
name: staging
|
|
||||||
url: https://stg-lti-erp.mbugroup.id
|
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
npm run format
|
npm run format
|
||||||
npm run lint
|
npm run lint
|
||||||
npx tsc --noEmit
|
npm run build
|
||||||
Generated
+43
-4369
File diff suppressed because it is too large
Load Diff
+4
-21
@@ -15,37 +15,20 @@
|
|||||||
"@tanstack/match-sorter-utils": "^8.19.4",
|
"@tanstack/match-sorter-utils": "^8.19.4",
|
||||||
"@tanstack/react-table": "^8.21.3",
|
"@tanstack/react-table": "^8.21.3",
|
||||||
"axios": "^1.12.2",
|
"axios": "^1.12.2",
|
||||||
"class-variance-authority": "^0.7.1",
|
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"cmdk": "^1.1.1",
|
|
||||||
"embla-carousel-react": "^8.6.0",
|
|
||||||
"exceljs": "^4.4.0",
|
|
||||||
"formik": "^2.4.6",
|
"formik": "^2.4.6",
|
||||||
"html-to-image": "^1.11.13",
|
|
||||||
"input-otp": "^1.4.2",
|
|
||||||
"jspdf": "^3.0.4",
|
|
||||||
"jspdf-autotable": "^5.0.2",
|
|
||||||
"lucide-react": "^0.562.0",
|
|
||||||
"moment": "^2.30.1",
|
"moment": "^2.30.1",
|
||||||
"next": "15.5.9",
|
"next": "^15.5.7",
|
||||||
"next-themes": "^0.4.6",
|
"react": "19.1.0",
|
||||||
"radix-ui": "^1.4.3",
|
|
||||||
"react": "^19.1.2",
|
|
||||||
"react-day-picker": "^9.11.1",
|
"react-day-picker": "^9.11.1",
|
||||||
"react-dom": "^19.1.2",
|
"react-dom": "19.1.0",
|
||||||
"react-dropzone": "^14.3.8",
|
"react-dropzone": "^14.3.8",
|
||||||
"react-hook-form": "^7.70.0",
|
|
||||||
"react-hot-toast": "^2.6.0",
|
"react-hot-toast": "^2.6.0",
|
||||||
"react-number-format": "^5.4.4",
|
"react-number-format": "^5.4.4",
|
||||||
"react-resizable-panels": "2.1.7",
|
|
||||||
"react-select": "^5.10.2",
|
"react-select": "^5.10.2",
|
||||||
"recharts": "^3.6.0",
|
|
||||||
"sonner": "^2.0.7",
|
|
||||||
"swr": "^2.3.6",
|
"swr": "^2.3.6",
|
||||||
"tailwind-merge": "^3.3.1",
|
"tailwind-merge": "^3.3.1",
|
||||||
"use-debounce": "^10.0.6",
|
"use-debounce": "^10.0.6",
|
||||||
"vaul": "^1.1.2",
|
|
||||||
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz",
|
|
||||||
"yup": "^1.7.0",
|
"yup": "^1.7.0",
|
||||||
"zustand": "^5.0.8"
|
"zustand": "^5.0.8"
|
||||||
},
|
},
|
||||||
@@ -56,7 +39,7 @@
|
|||||||
"@types/node": "^20",
|
"@types/node": "^20",
|
||||||
"@types/react": "^19",
|
"@types/react": "^19",
|
||||||
"@types/react-dom": "^19",
|
"@types/react-dom": "^19",
|
||||||
"daisyui": "^5.5.14",
|
"daisyui": "^5.5.8",
|
||||||
"eslint": "^9",
|
"eslint": "^9",
|
||||||
"eslint-config-next": "^15.5.7",
|
"eslint-config-next": "^15.5.7",
|
||||||
"husky": "^9.1.7",
|
"husky": "^9.1.7",
|
||||||
|
|||||||
@@ -7,58 +7,21 @@ import ClosingDetail from '@/components/pages/closing/ClosingDetail';
|
|||||||
|
|
||||||
import { ClosingApi } from '@/services/api/closing';
|
import { ClosingApi } from '@/services/api/closing';
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
import { FlockApi } from '@/services/api/master-data';
|
|
||||||
import { ProjectFlockApi } from '@/services/api/production/project-flock';
|
|
||||||
import { ProjectFlockKandangApi } from '@/services/api/production';
|
|
||||||
|
|
||||||
const ClosingDetailPage = () => {
|
const ClosingDetailPage = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const searchParams = useSearchParams();
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
const closingId = searchParams.get('closingId');
|
const closingId = searchParams.get('closingId');
|
||||||
const kandangId = searchParams.get('kandangId'); // project flock kandang ID
|
|
||||||
|
|
||||||
const { data: closing, isLoading: isLoadingClosing } = useSWR(
|
const { data: closing, isLoading: isLoadingClosing } = useSWR(
|
||||||
closingId,
|
closingId,
|
||||||
(id: number) => ClosingApi.getGeneralInfo(id)
|
(id: number) => ClosingApi.getGeneralInfo(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
// WORKAROUND - get flock data from closing ID
|
|
||||||
const { data: projectData, isLoading: isLoadingProject } = useSWR(
|
|
||||||
`flock-${closingId}`,
|
|
||||||
() => ProjectFlockApi.getSingle(Number(closingId))
|
|
||||||
);
|
|
||||||
// WORKAROUND - get kandang data from closing ID
|
|
||||||
const { data: kandangData, isLoading: isLoadingKandang } = useSWR(
|
|
||||||
kandangId ? `kandang-${closingId}-${kandangId}` : null,
|
|
||||||
() => ProjectFlockKandangApi.getSingle(Number(kandangId))
|
|
||||||
);
|
|
||||||
|
|
||||||
const { data: salesData, isLoading: isLoadingSales } = useSWR(
|
const { data: salesData, isLoading: isLoadingSales } = useSWR(
|
||||||
kandangId
|
closingId ? `sales-${closingId}` : null,
|
||||||
? `sales-${closingId}-${kandangId}`
|
() => ClosingApi.getPenjualan(Number(closingId))
|
||||||
: closingId
|
|
||||||
? `sales-${closingId}`
|
|
||||||
: null,
|
|
||||||
() =>
|
|
||||||
kandangId
|
|
||||||
? ClosingApi.getPenjualanByKandang(Number(closingId), Number(kandangId))
|
|
||||||
: ClosingApi.getPenjualan(Number(closingId))
|
|
||||||
);
|
|
||||||
|
|
||||||
const { data: hppEkspedisiData, isLoading: isLoadingHppEkspedisi } = useSWR(
|
|
||||||
kandangId
|
|
||||||
? `hpp-ekspedisi-${closingId}-${kandangId}`
|
|
||||||
: closingId
|
|
||||||
? `hpp-ekspedisi-${closingId}`
|
|
||||||
: null,
|
|
||||||
() =>
|
|
||||||
kandangId
|
|
||||||
? ClosingApi.getHppEkspedisiByKandang(
|
|
||||||
Number(closingId),
|
|
||||||
Number(kandangId)
|
|
||||||
)
|
|
||||||
: ClosingApi.getHppEkspedisi(Number(closingId))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!closingId) {
|
if (!closingId) {
|
||||||
@@ -76,12 +39,7 @@ const ClosingDetailPage = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isLoading =
|
const isLoading = isLoadingClosing || isLoadingSales;
|
||||||
isLoadingClosing ||
|
|
||||||
isLoadingSales ||
|
|
||||||
isLoadingHppEkspedisi ||
|
|
||||||
isLoadingProject ||
|
|
||||||
isLoadingKandang;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='w-full p-4 flex flex-row justify-center'>
|
<div className='w-full p-4 flex flex-row justify-center'>
|
||||||
@@ -92,17 +50,6 @@ const ClosingDetailPage = () => {
|
|||||||
id={Number(closingId)}
|
id={Number(closingId)}
|
||||||
initialValue={closing.data}
|
initialValue={closing.data}
|
||||||
salesData={isResponseSuccess(salesData) ? salesData.data : undefined}
|
salesData={isResponseSuccess(salesData) ? salesData.data : undefined}
|
||||||
hppExpeditionData={
|
|
||||||
isResponseSuccess(hppEkspedisiData)
|
|
||||||
? hppEkspedisiData.data
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
projectData={
|
|
||||||
isResponseSuccess(projectData) ? projectData.data : undefined
|
|
||||||
}
|
|
||||||
kandangData={
|
|
||||||
isResponseSuccess(kandangData) ? kandangData.data : undefined
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
import { DailyChecklistContent } from '@/figma-make/components/pages/daily-checklist/DailyChecklistContent';
|
|
||||||
|
|
||||||
const DailyChecklistPage = () => {
|
|
||||||
return (
|
|
||||||
<section className='w-full'>
|
|
||||||
<DailyChecklistContent />
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DailyChecklistPage;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { Dashboard as DashboardDailyChecklist } from '@/figma-make/components/pages/dashboard/Dashboard';
|
|
||||||
|
|
||||||
const DailyChecklistDashboardPage = () => {
|
|
||||||
return (
|
|
||||||
<section className='w-full'>
|
|
||||||
<DashboardDailyChecklist />
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DailyChecklistDashboardPage;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { DetailDailyChecklistContent } from '@/figma-make/components/pages/list-daily-checklist/detail/DetailDailyChecklistContent';
|
|
||||||
|
|
||||||
const ListDailyChecklistDetailPage = () => {
|
|
||||||
return (
|
|
||||||
<section className='w-full'>
|
|
||||||
<DetailDailyChecklistContent />
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ListDailyChecklistDetailPage;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { ListDailyChecklistContent } from '@/figma-make/components/pages/list-daily-checklist/ListDailyChecklistContent';
|
|
||||||
|
|
||||||
const ListDailyChecklistPage = () => {
|
|
||||||
return (
|
|
||||||
<section className='w-full'>
|
|
||||||
<ListDailyChecklistContent />
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ListDailyChecklistPage;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { MasterAktivitasContent } from '@/figma-make/components/pages/master-data/activity/MasterAktivitasContent';
|
|
||||||
|
|
||||||
const MasterAktivitasPage = () => {
|
|
||||||
return (
|
|
||||||
<section className='w-full'>
|
|
||||||
<MasterAktivitasContent />
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MasterAktivitasPage;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { MasterConfigurationContent } from '@/figma-make/components/pages/master-data/configuration/MasterConfigurationContent';
|
|
||||||
|
|
||||||
const MasterConfigurationPage = () => {
|
|
||||||
return (
|
|
||||||
<section className='w-full'>
|
|
||||||
<MasterConfigurationContent />
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MasterConfigurationPage;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { MasterEmployeeContent } from '@/figma-make/components/pages/master-data/employee/MasterEmployeeContent';
|
|
||||||
|
|
||||||
const MasterEmployeePage = () => {
|
|
||||||
return (
|
|
||||||
<section className='w-full'>
|
|
||||||
<MasterEmployeeContent />
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MasterEmployeePage;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import { DailyChecklistReportsContent } from '@/figma-make/components/pages/reports/DailyChecklistReportsContent';
|
|
||||||
|
|
||||||
const DailyChecklistReportsPage = () => {
|
|
||||||
return (
|
|
||||||
<section className='w-full'>
|
|
||||||
<DailyChecklistReportsContent />
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DailyChecklistReportsPage;
|
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import DashboardProduction from '@/components/pages/dashboard/DashboardProduction';
|
|
||||||
|
|
||||||
const Dashboard = () => {
|
const Dashboard = () => {
|
||||||
return <DashboardProduction />;
|
return (
|
||||||
|
<section className='w-full p-4'>
|
||||||
|
<h1 className='text-3xl font-bold text-primary'>Dashboard</h1>
|
||||||
|
</section>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Dashboard;
|
export default Dashboard;
|
||||||
|
|||||||
@@ -38,11 +38,9 @@ const ExpenseEditPage = () => {
|
|||||||
!isLoadingExpense &&
|
!isLoadingExpense &&
|
||||||
isResponseSuccess(expense) &&
|
isResponseSuccess(expense) &&
|
||||||
expense.data.latest_approval.step_number !== 5 &&
|
expense.data.latest_approval.step_number !== 5 &&
|
||||||
expense.data.latest_approval.step_number !== 6 &&
|
|
||||||
(expense.data.latest_approval.step_number === 1 ||
|
(expense.data.latest_approval.step_number === 1 ||
|
||||||
expense.data.latest_approval.step_number === 2 ||
|
expense.data.latest_approval.step_number === 2 ||
|
||||||
expense.data.latest_approval.step_number === 3 ||
|
expense.data.latest_approval.step_number === 3);
|
||||||
expense.data.latest_approval.step_number === 4);
|
|
||||||
|
|
||||||
if (!isLoadingExpense && !isExpenseCanBeEdited) {
|
if (!isLoadingExpense && !isExpenseCanBeEdited) {
|
||||||
router.back();
|
router.back();
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import ExpensesTable from '@/components/pages/expense/ExpensesTable';
|
|||||||
|
|
||||||
const Expense = () => {
|
const Expense = () => {
|
||||||
return (
|
return (
|
||||||
<section className='w-full p-4 sm:p-0'>
|
<section className='w-full p-4'>
|
||||||
<ExpensesTable />
|
<ExpensesTable />
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ const ExpenseRealizationEditPage = () => {
|
|||||||
!isLoadingExpense &&
|
!isLoadingExpense &&
|
||||||
isResponseSuccess(expense) &&
|
isResponseSuccess(expense) &&
|
||||||
expense.data.latest_approval.action !== 'REJECTED' &&
|
expense.data.latest_approval.action !== 'REJECTED' &&
|
||||||
(expense.data.latest_approval.step_number === 5 ||
|
(expense.data.latest_approval.step_number === 4 ||
|
||||||
expense.data.latest_approval.step_number === 6);
|
expense.data.latest_approval.step_number === 5);
|
||||||
|
|
||||||
if (!isLoadingExpense && !isExpenseRealizationCanBeEdited) {
|
if (!isLoadingExpense && !isExpenseRealizationCanBeEdited) {
|
||||||
router.back();
|
router.back();
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ const ExpenseRealization = () => {
|
|||||||
const isExpenseCanBeRealized =
|
const isExpenseCanBeRealized =
|
||||||
isResponseSuccess(expense) &&
|
isResponseSuccess(expense) &&
|
||||||
expense.data.latest_approval.action !== 'REJECTED' &&
|
expense.data.latest_approval.action !== 'REJECTED' &&
|
||||||
expense.data.latest_approval.step_number === 4;
|
expense.data.latest_approval.step_number === 3;
|
||||||
|
|
||||||
if (isResponseSuccess(expense) && !isExpenseCanBeRealized) {
|
if (isResponseSuccess(expense) && !isExpenseCanBeRealized) {
|
||||||
if (typeof window !== 'undefined') {
|
if (typeof window !== 'undefined') {
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
const FinanceAdjust = () => {
|
|
||||||
return <div>Finance Adjust</div>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default FinanceAdjust;
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import FormFinanceAddInitialBalance from '@/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance';
|
|
||||||
|
|
||||||
const FinanceAddInitialBalancePage = () => {
|
|
||||||
return <FormFinanceAddInitialBalance type='add' />;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default FinanceAddInitialBalancePage;
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import FormFinanceInjection from '@/components/pages/finance/add/injection/FormFinanceInjection';
|
|
||||||
|
|
||||||
const FinanceAddInjectionPage = () => {
|
|
||||||
return <FormFinanceInjection type='add' />;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default FinanceAddInjectionPage;
|
|
||||||
@@ -1,7 +1,16 @@
|
|||||||
import FormFinanceAdd from '@/components/pages/finance/add/FormFinanceAdd';
|
import FinanceForm from '@/components/pages/finance/form/FinanceForm';
|
||||||
|
import { Metadata } from 'next';
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: 'Finance | Add',
|
||||||
|
};
|
||||||
|
|
||||||
const FinanceAddPage = () => {
|
const FinanceAddPage = () => {
|
||||||
return <FormFinanceAdd />;
|
return (
|
||||||
|
<div className='w-full p-4 flex flex-row justify-center'>
|
||||||
|
<FinanceForm formType='add' />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default FinanceAddPage;
|
export default FinanceAddPage;
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
|
||||||
import useSWR from 'swr';
|
|
||||||
import { FinanceApi } from '@/services/api/finance';
|
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
|
||||||
import FormFinanceAddInitialBalance from '@/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance';
|
|
||||||
|
|
||||||
const EditFinanceInitialBalancePage = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const searchParams = useSearchParams();
|
|
||||||
|
|
||||||
const financeId = searchParams.get('financeId');
|
|
||||||
|
|
||||||
const { data: finance, isLoading: isLoadingFinance } = useSWR(
|
|
||||||
financeId,
|
|
||||||
(id: number) => FinanceApi.getSingle(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!financeId) {
|
|
||||||
router.back();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='w-full flex flex-row justify-center items-center p-4'>
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isLoadingFinance && (!finance || isResponseError(finance))) {
|
|
||||||
router.replace('/404');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='w-full p-4 flex flex-row justify-center'>
|
|
||||||
{isLoadingFinance && (
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!isLoadingFinance && (
|
|
||||||
<FormFinanceAddInitialBalance
|
|
||||||
type='edit'
|
|
||||||
initialValues={isResponseSuccess(finance) ? finance.data : undefined}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default EditFinanceInitialBalancePage;
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
|
||||||
import useSWR from 'swr';
|
|
||||||
import { FinanceApi } from '@/services/api/finance';
|
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
|
||||||
import FormFinanceInjection from '@/components/pages/finance/add/injection/FormFinanceInjection';
|
|
||||||
|
|
||||||
const EditFinanceInjectionPage = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const searchParams = useSearchParams();
|
|
||||||
|
|
||||||
const financeId = searchParams.get('financeId');
|
|
||||||
|
|
||||||
const { data: finance, isLoading: isLoadingFinance } = useSWR(
|
|
||||||
financeId,
|
|
||||||
(id: number) => FinanceApi.getSingle(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!financeId) {
|
|
||||||
router.back();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='w-full flex flex-row justify-center items-center p-4'>
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isLoadingFinance && (!finance || isResponseError(finance))) {
|
|
||||||
router.replace('/404');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='w-full p-4 flex flex-row justify-center'>
|
|
||||||
{isLoadingFinance && (
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!isLoadingFinance && (
|
|
||||||
<FormFinanceInjection
|
|
||||||
type='edit'
|
|
||||||
initialValues={isResponseSuccess(finance) ? finance.data : undefined}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default EditFinanceInjectionPage;
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
|
||||||
import useSWR from 'swr';
|
|
||||||
import { FinanceApi } from '@/services/api/finance';
|
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
|
||||||
import FormFinanceAdd from '@/components/pages/finance/add/FormFinanceAdd';
|
|
||||||
import FormFinanceAddInitialBalance from '@/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance';
|
|
||||||
|
|
||||||
const EditFinanceTransactionPage = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const searchParams = useSearchParams();
|
|
||||||
|
|
||||||
const financeId = searchParams.get('financeId');
|
|
||||||
|
|
||||||
const { data: finance, isLoading: isLoadingFinance } = useSWR(
|
|
||||||
financeId,
|
|
||||||
(id: number) => FinanceApi.getSingle(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!financeId) {
|
|
||||||
router.back();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='w-full flex flex-row justify-center items-center p-4'>
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isLoadingFinance && (!finance || isResponseError(finance))) {
|
|
||||||
router.replace('/404');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='w-full p-4 flex flex-row justify-center'>
|
|
||||||
{isLoadingFinance && (
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!isLoadingFinance && (
|
|
||||||
<FormFinanceAdd
|
|
||||||
type='edit'
|
|
||||||
initialValues={isResponseSuccess(finance) ? finance.data : undefined}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default EditFinanceTransactionPage;
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import FinanceDetail from '@/components/pages/finance/FinanceDetail';
|
|
||||||
import useSWR from 'swr';
|
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
|
||||||
import { FinanceApi } from '@/services/api/finance';
|
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
|
||||||
|
|
||||||
const FinanceDetailPage = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const financeId = useSearchParams().get('financeId');
|
|
||||||
|
|
||||||
const { data: finance } = useSWR(financeId, () =>
|
|
||||||
FinanceApi.getSingle(Number(financeId))
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!financeId) {
|
|
||||||
router.back();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='w-full flex flex-row justify-center items-center p-4'>
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (!finance || isResponseError(finance)) {
|
|
||||||
// router.replace('/404');
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{isResponseSuccess(finance) && <FinanceDetail finance={finance.data} />}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default FinanceDetailPage;
|
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
'use client';
|
import FinancesTable from '@/components/pages/finance/FinancesTable';
|
||||||
|
|
||||||
import FinanceTable from '@/components/pages/finance/FinanceTable';
|
|
||||||
|
|
||||||
const Finance = () => {
|
const Finance = () => {
|
||||||
return (
|
return (
|
||||||
<section className='size-full p-6'>
|
<section className='w-full p-4'>
|
||||||
<div className='flex flex-row gap-4'></div>
|
<FinancesTable />
|
||||||
<FinanceTable />
|
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
+5
-11
@@ -1,8 +1,6 @@
|
|||||||
@import 'tailwindcss';
|
@import 'tailwindcss';
|
||||||
@plugin "daisyui";
|
@plugin "daisyui";
|
||||||
@import '../styles/tailwind.css';
|
|
||||||
@import '../styles/daisyui.css';
|
@import '../styles/daisyui.css';
|
||||||
@import '../figma-make/styles/theme.css';
|
|
||||||
|
|
||||||
@plugin "daisyui/theme" {
|
@plugin "daisyui/theme" {
|
||||||
name: 'lti';
|
name: 'lti';
|
||||||
@@ -30,16 +28,16 @@
|
|||||||
--color-base-100: oklch(100% 0 0); /* #ffffff */
|
--color-base-100: oklch(100% 0 0); /* #ffffff */
|
||||||
--color-base-200: oklch(97.2% 0 0); /* #f2f2f2 */
|
--color-base-200: oklch(97.2% 0 0); /* #f2f2f2 */
|
||||||
--color-base-300: oklch(93.1% 0.002 249.7); /* #e5e6e6 */
|
--color-base-300: oklch(93.1% 0.002 249.7); /* #e5e6e6 */
|
||||||
--color-base-content: #18181b;
|
--color-base-content: oklch(18.6% 0.024 257.7); /* #1f2937 */
|
||||||
|
|
||||||
/* Status/Utility Colors */
|
/* Status/Utility Colors */
|
||||||
--color-info: oklch(67.4% 0.176 238.9);
|
--color-info: oklch(67.4% 0.176 238.9);
|
||||||
--color-info-content: oklch(0% 0 0); /* #000000 */
|
--color-info-content: oklch(0% 0 0); /* #000000 */
|
||||||
--color-success: #00d390;
|
--color-success: oklch(62.3% 0.147 149);
|
||||||
--color-success-content: oklch(100% 0 0); /* #ffffff */
|
--color-success-content: oklch(100% 0 0); /* #ffffff */
|
||||||
--color-warning: #fcb700;
|
--color-warning: oklch(82.2% 0.165 91.9);
|
||||||
--color-warning-content: oklch(0% 0 0); /* #000000 */
|
--color-warning-content: oklch(0% 0 0); /* #000000 */
|
||||||
--color-error: #ff3a3a;
|
--color-error: oklch(61.8% 0.203 27.8);
|
||||||
--color-error-content: oklch(100% 0 0); /* #fffffff */
|
--color-error-content: oklch(100% 0 0); /* #fffffff */
|
||||||
|
|
||||||
--radius-selector: 0rem;
|
--radius-selector: 0rem;
|
||||||
@@ -53,21 +51,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
:root {
|
:root {
|
||||||
--color-primary: #0069e0;
|
--color-primary: #1f74bf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@theme {
|
@theme {
|
||||||
--font-inter: var(--font-inter);
|
--font-inter: var(--font-inter);
|
||||||
--font-roboto: var(--font-roboto);
|
|
||||||
|
|
||||||
--container-sm: 40rem;
|
--container-sm: 40rem;
|
||||||
--container-md: 48rem;
|
--container-md: 48rem;
|
||||||
--container-lg: 64rem;
|
--container-lg: 64rem;
|
||||||
--container-xl: 80rem;
|
--container-xl: 80rem;
|
||||||
--container-2xl: 96rem;
|
--container-2xl: 96rem;
|
||||||
|
|
||||||
--shadow-button-soft:
|
|
||||||
0 3px 2px -2px var(--color-base-200), 0 4px 3px -2px var(--color-base-200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
html {
|
html {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import MovementTable from '@/components/pages/inventory/movement/MovementTable';
|
|||||||
|
|
||||||
const Movement = () => {
|
const Movement = () => {
|
||||||
return (
|
return (
|
||||||
<section className='w-full p-4 sm:p-0'>
|
<section className='w-full p-4'>
|
||||||
<MovementTable />
|
<MovementTable />
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|||||||
+2
-12
@@ -1,9 +1,8 @@
|
|||||||
import type { Metadata, Viewport } from 'next';
|
import type { Metadata, Viewport } from 'next';
|
||||||
import { Inter, Roboto } from 'next/font/google';
|
import { Inter } from 'next/font/google';
|
||||||
import '@/app/globals.css';
|
import '@/app/globals.css';
|
||||||
|
|
||||||
import { Toaster } from 'react-hot-toast';
|
import { Toaster } from 'react-hot-toast';
|
||||||
import { Toaster as SonnerToaster } from '@/figma-make/components/base/sonner';
|
|
||||||
import MainDrawer from '@/components/MainDrawer';
|
import MainDrawer from '@/components/MainDrawer';
|
||||||
import RequireAuth from '@/components/helper/RequireAuth';
|
import RequireAuth from '@/components/helper/RequireAuth';
|
||||||
|
|
||||||
@@ -12,12 +11,6 @@ const inter = Inter({
|
|||||||
subsets: ['latin'],
|
subsets: ['latin'],
|
||||||
});
|
});
|
||||||
|
|
||||||
const roboto = Roboto({
|
|
||||||
variable: '--font-roboto',
|
|
||||||
subsets: ['latin'],
|
|
||||||
weight: ['200', '300', '400', '500', '600', '700', '900'],
|
|
||||||
});
|
|
||||||
|
|
||||||
export const viewport: Viewport = {
|
export const viewport: Viewport = {
|
||||||
themeColor: '#1f74bf',
|
themeColor: '#1f74bf',
|
||||||
colorScheme: 'light',
|
colorScheme: 'light',
|
||||||
@@ -36,15 +29,12 @@ export default function RootLayout({
|
|||||||
}>) {
|
}>) {
|
||||||
return (
|
return (
|
||||||
<html lang='en' data-theme='lti'>
|
<html lang='en' data-theme='lti'>
|
||||||
<body
|
<body className={`${inter.variable} antialiased font-inter`}>
|
||||||
className={`${inter.variable} ${roboto.variable} antialiased font-inter`}
|
|
||||||
>
|
|
||||||
<RequireAuth>
|
<RequireAuth>
|
||||||
<MainDrawer>{children}</MainDrawer>
|
<MainDrawer>{children}</MainDrawer>
|
||||||
</RequireAuth>
|
</RequireAuth>
|
||||||
|
|
||||||
<Toaster />
|
<Toaster />
|
||||||
<SonnerToaster position='top-right' />
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
import DeliveryOrderFormModal from '@/components/pages/marketing/DeliveryOrderFormModal';
|
|
||||||
import MarketingTable from '@/components/pages/marketing/MarketingTable';
|
import MarketingTable from '@/components/pages/marketing/MarketingTable';
|
||||||
import SalesOrderFormModal from '@/components/pages/marketing/SalesOrderFormModal';
|
|
||||||
|
|
||||||
const Marketing = () => {
|
const Marketing = () => {
|
||||||
return (
|
return (
|
||||||
<div className='w-full'>
|
<div className='w-full p-4'>
|
||||||
<MarketingTable />
|
<MarketingTable />
|
||||||
|
|
||||||
<SalesOrderFormModal />
|
|
||||||
<DeliveryOrderFormModal />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import ProductionStandardForm from '@/components/pages/master-data/production-standard/form/ProductionStandardForm';
|
|
||||||
|
|
||||||
const AddProductionStandardPage = () => {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<ProductionStandardForm formType='add' />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default AddProductionStandardPage;
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import ProductionStandardForm from '@/components/pages/master-data/production-standard/form/ProductionStandardForm';
|
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
|
||||||
import { ProductionStandardApi } from '@/services/api/master-data';
|
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
|
||||||
import useSWR from 'swr';
|
|
||||||
|
|
||||||
const EditProductionStandardPage = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const searchParams = useSearchParams();
|
|
||||||
|
|
||||||
// Get Query Params
|
|
||||||
const productionStandardId = searchParams.get('productionStandardId');
|
|
||||||
|
|
||||||
// Fetch Data
|
|
||||||
const { data: productionStandard, isLoading: isLoadingProductionStandard } =
|
|
||||||
useSWR(productionStandardId, (id: number) =>
|
|
||||||
ProductionStandardApi.getSingle(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!productionStandardId) {
|
|
||||||
router.back();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='w-full flex flex-row justify-center items-center p-4'>
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
!isLoadingProductionStandard &&
|
|
||||||
(!productionStandard || isResponseError(productionStandard))
|
|
||||||
) {
|
|
||||||
router.replace('/404');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{isLoadingProductionStandard && (
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
)}
|
|
||||||
{!isLoadingProductionStandard &&
|
|
||||||
isResponseSuccess(productionStandard) && (
|
|
||||||
<ProductionStandardForm
|
|
||||||
formType='edit'
|
|
||||||
initialValue={productionStandard.data}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default EditProductionStandardPage;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import SuspenseHelper from '@/components/helper/SuspenseHelper';
|
|
||||||
|
|
||||||
const Layout = ({
|
|
||||||
children,
|
|
||||||
}: Readonly<{
|
|
||||||
children: React.ReactNode;
|
|
||||||
}>) => {
|
|
||||||
return <SuspenseHelper>{children}</SuspenseHelper>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Layout;
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import ProductionStandardForm from '@/components/pages/master-data/production-standard/form/ProductionStandardForm';
|
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
|
||||||
import { ProductionStandardApi } from '@/services/api/master-data';
|
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
|
||||||
import useSWR from 'swr';
|
|
||||||
|
|
||||||
const DetailProductionStandardPage = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const searchParams = useSearchParams();
|
|
||||||
|
|
||||||
// Get Query Params
|
|
||||||
const productionStandardId = searchParams.get('productionStandardId');
|
|
||||||
|
|
||||||
// Fetch Data
|
|
||||||
const { data: productionStandard, isLoading: isLoadingProductionStandard } =
|
|
||||||
useSWR(productionStandardId, (id: number) =>
|
|
||||||
ProductionStandardApi.getSingle(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!productionStandardId) {
|
|
||||||
router.back();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='w-full flex flex-row justify-center items-center p-4'>
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
!isLoadingProductionStandard &&
|
|
||||||
(!productionStandard || isResponseError(productionStandard))
|
|
||||||
) {
|
|
||||||
router.replace('/404');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{isLoadingProductionStandard && (
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
)}
|
|
||||||
{!isLoadingProductionStandard &&
|
|
||||||
isResponseSuccess(productionStandard) && (
|
|
||||||
<ProductionStandardForm
|
|
||||||
formType='detail'
|
|
||||||
initialValue={productionStandard.data}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DetailProductionStandardPage;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import ProductionStandardTable from '@/components/pages/master-data/production-standard/ProductionStandardTable';
|
|
||||||
|
|
||||||
const ProductionStandardPage = () => {
|
|
||||||
return (
|
|
||||||
<div className='w-full'>
|
|
||||||
<ProductionStandardTable />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ProductionStandardPage;
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
import PageNotFound from '@/components/helper/NotFoundPage';
|
|
||||||
|
|
||||||
export default function NotFound() {
|
|
||||||
return <PageNotFound />;
|
|
||||||
}
|
|
||||||
+1
-5
@@ -25,9 +25,5 @@ export default function Home() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return <>Loading...</>;
|
||||||
<main className='w-full h-full min-h-screen flex flex-row justify-center items-center'>
|
|
||||||
<span className='loading loading-spinner loading-lg'></span>
|
|
||||||
</main>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { FormHeader } from '@/components/helper/form/FormHeader';
|
||||||
|
import ProjectFlockChickinDetail from '@/components/pages/production/project-flock/chickin/ProjectFlockChickinDetail';
|
||||||
|
import { useSearchParams } from 'next/navigation';
|
||||||
|
|
||||||
|
const AddChickin = () => {
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
const projectFlockId = searchParams.get('projectFlockId');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<section className='w-full'>
|
||||||
|
<ProjectFlockChickinDetail projectFlockId={Number(projectFlockId)} />
|
||||||
|
</section>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AddChickin;
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
import ChickinTable from '@/components/pages/production/chickin/ChickinTable';
|
||||||
|
|
||||||
|
const Chickin = () => {
|
||||||
|
return (
|
||||||
|
<section className='w-full'>
|
||||||
|
<ChickinTable />
|
||||||
|
</section>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default Chickin;
|
||||||
@@ -14,13 +14,13 @@ const ProjectFlockClosingPage = () => {
|
|||||||
const projectFlockKandangId = searchParams.get('projectFlockKandangId');
|
const projectFlockKandangId = searchParams.get('projectFlockKandangId');
|
||||||
|
|
||||||
const { data: projectFlockKandang, isLoading: isLoadingProjectFlockKandang } =
|
const { data: projectFlockKandang, isLoading: isLoadingProjectFlockKandang } =
|
||||||
useSWR(`get-flock-kandang-id/${projectFlockKandangId}`, () =>
|
useSWR(projectFlockKandangId, (id: number) =>
|
||||||
ProjectFlockKandangApi.getSingle(parseInt(projectFlockKandangId ?? ''))
|
ProjectFlockKandangApi.getSingle(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data: projectFlock, isLoading: isLoadingProjectFlock } = useSWR(
|
const { data: projectFlock, isLoading: isLoadingProjectFlock } = useSWR(
|
||||||
`get-flock-id/${projectFlockId}`,
|
projectFlockId,
|
||||||
() => ProjectFlockApi.getSingle(parseInt(projectFlockId ?? ''))
|
(id: number) => ProjectFlockApi.getSingle(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!projectFlockId || !projectFlockKandangId) {
|
if (!projectFlockId || !projectFlockKandangId) {
|
||||||
|
|||||||
@@ -50,3 +50,5 @@ const ProjectFlockDetailPage = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default ProjectFlockDetailPage;
|
export default ProjectFlockDetailPage;
|
||||||
|
ProjectFlockDetail;
|
||||||
|
ProjectFlockDetail;
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export default function ProjectFlockLayout({
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const toggleValidate = useUiStore((s) => s.toggleValidate);
|
const toggleValidate = useUiStore((s) => s.toggleValidate);
|
||||||
|
|
||||||
const isAdd = pathname.includes('/add');
|
const isAdd = pathname.endsWith('/add');
|
||||||
const isEdit = pathname.includes('/detail/edit');
|
const isEdit = pathname.includes('/detail/edit');
|
||||||
const isDetail = pathname.includes('/detail');
|
const isDetail = pathname.includes('/detail');
|
||||||
const isChickin = pathname.includes('/chickin/add/kandang');
|
const isChickin = pathname.includes('/chickin/add/kandang');
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const RecordingEdit = () => {
|
|||||||
|
|
||||||
const { data: recording, isLoading: isLoadingRecording } = useSWR(
|
const { data: recording, isLoading: isLoadingRecording } = useSWR(
|
||||||
recordingId,
|
recordingId,
|
||||||
(id: string) => RecordingApi.getSingle(parseInt(id))
|
(id: number) => RecordingApi.getSingle(id) // Gunakan RecordingApi
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!recordingId) {
|
if (!recordingId) {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const RecordingDetail = () => {
|
|||||||
|
|
||||||
const { data: recording, isLoading: isLoadingRecording } = useSWR(
|
const { data: recording, isLoading: isLoadingRecording } = useSWR(
|
||||||
recordingId,
|
recordingId,
|
||||||
(id: string) => RecordingApi.getSingle(parseInt(id))
|
(id: number) => RecordingApi.getSingle(id)
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!recordingId) {
|
if (!recordingId) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import RecordingTable from '@/components/pages/production/recording/RecordingTab
|
|||||||
|
|
||||||
const Recording = () => {
|
const Recording = () => {
|
||||||
return (
|
return (
|
||||||
<section className='w-full p-4 sm:p-0'>
|
<section className='w-full p-4'>
|
||||||
<RecordingTable />
|
<RecordingTable />
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
import TransferToLayingForm from '@/components/pages/production/transfer-to-laying/form/TransferToLayingForm';
|
||||||
|
|
||||||
|
const AddTransferToLaying = () => {
|
||||||
|
return (
|
||||||
|
<div className='w-full p-4 flex flex-row justify-center'>
|
||||||
|
<TransferToLayingForm />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default AddTransferToLaying;
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
|
||||||
|
import TransferToLayingForm from '@/components/pages/production/transfer-to-laying/form/TransferToLayingForm';
|
||||||
|
|
||||||
|
import { TransferToLayingApi } from '@/services/api/production/transfer-to-laying';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
|
||||||
|
const TransferToLayingEdit = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const transferToLayingId = searchParams.get('transferToLayingId');
|
||||||
|
|
||||||
|
const { data: transferToLaying, isLoading: isLoadingTransferToLaying } =
|
||||||
|
useSWR(transferToLayingId, (id: number) =>
|
||||||
|
TransferToLayingApi.getSingle(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!transferToLayingId) {
|
||||||
|
router.back();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full flex flex-row justify-center items-center p-4'>
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!isLoadingTransferToLaying &&
|
||||||
|
(!transferToLaying || isResponseError(transferToLaying))
|
||||||
|
) {
|
||||||
|
router.replace('/404');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
isResponseSuccess(transferToLaying) &&
|
||||||
|
transferToLaying.data.approval.step_number === 2
|
||||||
|
) {
|
||||||
|
router.replace('/production/transfer-to-laying');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full p-4 flex flex-row justify-center'>
|
||||||
|
{isLoadingTransferToLaying && (
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
)}
|
||||||
|
{!isLoadingTransferToLaying && isResponseSuccess(transferToLaying) && (
|
||||||
|
<TransferToLayingForm
|
||||||
|
type='edit'
|
||||||
|
initialValues={transferToLaying.data}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TransferToLayingEdit;
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { useRouter, useSearchParams } from 'next/navigation';
|
||||||
|
import useSWR from 'swr';
|
||||||
|
|
||||||
|
import TransferToLayingForm from '@/components/pages/production/transfer-to-laying/form/TransferToLayingForm';
|
||||||
|
|
||||||
|
import { TransferToLayingApi } from '@/services/api/production/transfer-to-laying';
|
||||||
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
|
||||||
|
const TransferToLayingDetail = () => {
|
||||||
|
const router = useRouter();
|
||||||
|
const searchParams = useSearchParams();
|
||||||
|
|
||||||
|
const transferToLayingId = searchParams.get('transferToLayingId');
|
||||||
|
|
||||||
|
const { data: transferToLaying, isLoading: isLoadingTransferToLaying } =
|
||||||
|
useSWR(transferToLayingId, (id: number) =>
|
||||||
|
TransferToLayingApi.getSingle(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!transferToLayingId) {
|
||||||
|
router.back();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full flex flex-row justify-center items-center p-4'>
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!isLoadingTransferToLaying &&
|
||||||
|
(!transferToLaying || isResponseError(transferToLaying))
|
||||||
|
) {
|
||||||
|
router.replace('/404');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-full p-4 flex flex-row justify-center'>
|
||||||
|
{isLoadingTransferToLaying && (
|
||||||
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isLoadingTransferToLaying && isResponseSuccess(transferToLaying) && (
|
||||||
|
<TransferToLayingForm
|
||||||
|
type='detail'
|
||||||
|
initialValues={transferToLaying.data}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default TransferToLayingDetail;
|
||||||
@@ -1,25 +1,9 @@
|
|||||||
import TransferToLayingsTable from '@/components/pages/production/transfer-to-laying/TransferToLayingsTable';
|
import TransferToLayingsTable from '@/components/pages/production/transfer-to-laying/TransferToLayingsTable';
|
||||||
import TransferToLayingFormModal from '@/components/pages/production/transfer-to-laying/TransferToLayingFormModal';
|
|
||||||
import TransferToLayingDetailModal from '@/components/pages/production/transfer-to-laying/TransferToLayingDetailModal';
|
|
||||||
import RequirePermission from '@/components/helper/RequirePermission';
|
|
||||||
|
|
||||||
const TransferToLaying = () => {
|
const TransferToLaying = () => {
|
||||||
return (
|
return (
|
||||||
<section className='w-full'>
|
<section className='w-full p-4'>
|
||||||
<TransferToLayingsTable />
|
<TransferToLayingsTable />
|
||||||
|
|
||||||
<RequirePermission
|
|
||||||
permissions={[
|
|
||||||
'lti.production.transfer_to_laying.create',
|
|
||||||
'lti.production.transfer_to_laying.update',
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
<TransferToLayingFormModal />
|
|
||||||
</RequirePermission>
|
|
||||||
|
|
||||||
<RequirePermission permissions='lti.production.transfer_to_laying.detail'>
|
|
||||||
<TransferToLayingDetailModal />
|
|
||||||
</RequirePermission>
|
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
import UniformityForm from '@/components/pages/production/uniformity/form/UniformityForm';
|
|
||||||
|
|
||||||
const AddUniformity = () => {
|
|
||||||
return <UniformityForm formType='add' />;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default AddUniformity;
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import UniformityDetail from '@/components/pages/production/uniformity/detail/UniformityDetail';
|
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
|
||||||
import { UniformityApi } from '@/services/api/uniformity';
|
|
||||||
import { useRouter, useSearchParams } from 'next/navigation';
|
|
||||||
import useSWR from 'swr';
|
|
||||||
|
|
||||||
const UniformityDetailPage = () => {
|
|
||||||
const router = useRouter();
|
|
||||||
const searchParams = useSearchParams();
|
|
||||||
|
|
||||||
const uniformityId = searchParams.get('uniformityId');
|
|
||||||
|
|
||||||
const { data: uniformity, isLoading: isLoadingUniformity } = useSWR(
|
|
||||||
uniformityId,
|
|
||||||
(id: string) => UniformityApi.getUniformityDetail(parseInt(id))
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!uniformityId) {
|
|
||||||
router.back();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='w-full flex flex-row justify-center items-center p-4'>
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isLoadingUniformity && (!uniformity || isResponseError(uniformity))) {
|
|
||||||
router.replace('/404');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className='w-full h-full flex flex-col justify-center'>
|
|
||||||
{isLoadingUniformity && (
|
|
||||||
<div className='w-full flex flex-row justify-center items-center p-4 min-h-screen'>
|
|
||||||
<span className='loading loading-spinner loading-xl' />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
{isResponseSuccess(uniformity) && (
|
|
||||||
<UniformityDetail initialValues={uniformity.data} />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default UniformityDetailPage;
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import { ReactNode } from 'react';
|
|
||||||
import UniformityPageWrapper from '@/components/pages/production/uniformity/UniformityPageWrapper';
|
|
||||||
|
|
||||||
export default function UniformityLayout({
|
|
||||||
children,
|
|
||||||
}: {
|
|
||||||
children: ReactNode;
|
|
||||||
}) {
|
|
||||||
return <UniformityPageWrapper>{children}</UniformityPageWrapper>;
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import UniformityTable from '@/components/pages/production/uniformity/UniformityTable';
|
|
||||||
|
|
||||||
const Uniformity = () => {
|
|
||||||
return <UniformityTable />;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Uniformity;
|
|
||||||
@@ -2,7 +2,7 @@ import PurchaseTable from '@/components/pages/purchase/PurchaseTable';
|
|||||||
|
|
||||||
const Purchase = () => {
|
const Purchase = () => {
|
||||||
return (
|
return (
|
||||||
<section className='w-full p-4 sm:p-0'>
|
<section className='w-full p-4'>
|
||||||
<PurchaseTable />
|
<PurchaseTable />
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
import SuspenseHelper from '@/components/helper/SuspenseHelper';
|
|
||||||
|
|
||||||
const Layout = ({
|
|
||||||
children,
|
|
||||||
}: Readonly<{
|
|
||||||
children: React.ReactNode;
|
|
||||||
}>) => {
|
|
||||||
return <SuspenseHelper>{children}</SuspenseHelper>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Layout;
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
const ReportExpenseDetail = () => {
|
|
||||||
return <div>ReportExpenseDetail</div>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ReportExpenseDetail;
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import ReportExpenseTable from '@/components/pages/report/expense/ReportExpenseTable';
|
|
||||||
|
|
||||||
const ReportExpense = () => {
|
|
||||||
return (
|
|
||||||
<div className='w-full p-4'>
|
|
||||||
<ReportExpenseTable />
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ReportExpense;
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import FinanceTabs from '@/components/pages/report/finance/FinanceTabs';
|
|
||||||
|
|
||||||
const Finance = () => {
|
|
||||||
return <FinanceTabs />;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Finance;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import SuspenseHelper from '@/components/helper/SuspenseHelper';
|
|
||||||
|
|
||||||
const Layout = ({
|
|
||||||
children,
|
|
||||||
}: Readonly<{
|
|
||||||
children: React.ReactNode;
|
|
||||||
}>) => {
|
|
||||||
return <SuspenseHelper>{children}</SuspenseHelper>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Layout;
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
import LogisticStockTabs from '@/components/pages/report/logistic-stock/LogisticStockTabs';
|
|
||||||
|
|
||||||
const LogisticStock = () => {
|
|
||||||
return <LogisticStockTabs />;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default LogisticStock;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import SuspenseHelper from '@/components/helper/SuspenseHelper';
|
|
||||||
|
|
||||||
const Layout = ({
|
|
||||||
children,
|
|
||||||
}: Readonly<{
|
|
||||||
children: React.ReactNode;
|
|
||||||
}>) => {
|
|
||||||
return <SuspenseHelper>{children}</SuspenseHelper>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Layout;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import MarketingReportContent from '@/components/pages/report/MarketingReportContent';
|
|
||||||
|
|
||||||
const MarketingReportPage = () => {
|
|
||||||
return (
|
|
||||||
<section className='w-full p-4'>
|
|
||||||
<MarketingReportContent />
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default MarketingReportPage;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import ProductionResultContent from '@/components/pages/report/production-result/ProductionResultContent';
|
|
||||||
|
|
||||||
const ProductionResultReportPage = () => {
|
|
||||||
return (
|
|
||||||
<section className='w-full max-w-7xl pb-16'>
|
|
||||||
<ProductionResultContent />
|
|
||||||
</section>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ProductionResultReportPage;
|
|
||||||
+14
-34
@@ -3,25 +3,29 @@
|
|||||||
import { HTMLAttributes, ReactNode } from 'react';
|
import { HTMLAttributes, ReactNode } from 'react';
|
||||||
|
|
||||||
import { cn } from '@/lib/helper';
|
import { cn } from '@/lib/helper';
|
||||||
import type { Color, Variant, Size } from '@/types/theme';
|
|
||||||
|
|
||||||
export interface BadgeProps
|
export interface BadgeProps
|
||||||
extends Omit<HTMLAttributes<HTMLSpanElement>, 'className'> {
|
extends Omit<HTMLAttributes<HTMLSpanElement>, 'className'> {
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
className?: {
|
className?: {
|
||||||
badge?: string;
|
badge?: string;
|
||||||
status?: string;
|
|
||||||
};
|
};
|
||||||
statusIndicator?: boolean;
|
variant?: 'default' | 'outline' | 'ghost' | 'soft' | 'dash';
|
||||||
variant?: Variant;
|
color?:
|
||||||
color?: Color;
|
| 'neutral'
|
||||||
size?: Size;
|
| 'primary'
|
||||||
|
| 'secondary'
|
||||||
|
| 'accent'
|
||||||
|
| 'info'
|
||||||
|
| 'success'
|
||||||
|
| 'warning'
|
||||||
|
| 'error';
|
||||||
|
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
||||||
}
|
}
|
||||||
|
|
||||||
const Badge = ({
|
const Badge = ({
|
||||||
children,
|
children,
|
||||||
className,
|
className,
|
||||||
statusIndicator = false,
|
|
||||||
variant = 'default',
|
variant = 'default',
|
||||||
color,
|
color,
|
||||||
size = 'md',
|
size = 'md',
|
||||||
@@ -30,7 +34,7 @@ const Badge = ({
|
|||||||
const getBadgeClasses = () => {
|
const getBadgeClasses = () => {
|
||||||
const baseClasses = 'badge';
|
const baseClasses = 'badge';
|
||||||
|
|
||||||
const variantClasses: Record<Variant, string> = {
|
const variantClasses = {
|
||||||
default: '',
|
default: '',
|
||||||
outline: 'badge-outline',
|
outline: 'badge-outline',
|
||||||
ghost: 'badge-ghost',
|
ghost: 'badge-ghost',
|
||||||
@@ -38,7 +42,7 @@ const Badge = ({
|
|||||||
dash: 'badge-dash',
|
dash: 'badge-dash',
|
||||||
};
|
};
|
||||||
|
|
||||||
const colorClasses: Record<Color, string> = {
|
const colorClasses = {
|
||||||
neutral: 'badge-neutral',
|
neutral: 'badge-neutral',
|
||||||
primary: 'badge-primary',
|
primary: 'badge-primary',
|
||||||
secondary: 'badge-secondary',
|
secondary: 'badge-secondary',
|
||||||
@@ -47,10 +51,9 @@ const Badge = ({
|
|||||||
success: 'badge-success',
|
success: 'badge-success',
|
||||||
warning: 'badge-warning',
|
warning: 'badge-warning',
|
||||||
error: 'badge-error',
|
error: 'badge-error',
|
||||||
none: '',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const sizeClasses: Record<Size, string> = {
|
const sizeClasses = {
|
||||||
xs: 'badge-xs',
|
xs: 'badge-xs',
|
||||||
sm: 'badge-sm',
|
sm: 'badge-sm',
|
||||||
md: 'badge-md',
|
md: 'badge-md',
|
||||||
@@ -67,31 +70,8 @@ const Badge = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getStatusClasses = () => {
|
|
||||||
if (!statusIndicator) return '';
|
|
||||||
|
|
||||||
const statusIndicatorClasses: Record<Color, string> = {
|
|
||||||
neutral: 'bg-neutral',
|
|
||||||
primary: 'bg-primary',
|
|
||||||
secondary: 'bg-secondary',
|
|
||||||
accent: 'bg-accent',
|
|
||||||
info: 'bg-info',
|
|
||||||
success: 'bg-success',
|
|
||||||
warning: 'bg-warning',
|
|
||||||
error: 'bg-error',
|
|
||||||
none: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
return cn(
|
|
||||||
'w-2.5 h-2.5 rounded-full',
|
|
||||||
color && statusIndicatorClasses[color],
|
|
||||||
className?.status
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span className={getBadgeClasses()} {...props}>
|
<span className={getBadgeClasses()} {...props}>
|
||||||
{statusIndicator && <span className={getStatusClasses()} />}
|
|
||||||
{children}
|
{children}
|
||||||
</span>
|
</span>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,263 +0,0 @@
|
|||||||
import React, { useId } from 'react';
|
|
||||||
import Link from 'next/link';
|
|
||||||
import { Icon } from '@iconify/react';
|
|
||||||
import { cn, findMenuPath } from '@/lib/helper';
|
|
||||||
import { Size } from '@/types/theme';
|
|
||||||
import Button from '@/components/Button';
|
|
||||||
import { MAIN_DRAWER_LINKS } from '@/config/constant';
|
|
||||||
|
|
||||||
interface BreadcrumbItem {
|
|
||||||
label: string;
|
|
||||||
href?: string;
|
|
||||||
icon?: React.ReactNode;
|
|
||||||
isActive?: boolean;
|
|
||||||
isDisabled?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface BreadcrumbsProps extends React.HTMLAttributes<HTMLElement> {
|
|
||||||
items: BreadcrumbItem[];
|
|
||||||
size?: Size;
|
|
||||||
maxVisibleItems?: number;
|
|
||||||
showEllipsisDropdown?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildBreadcrumbs(pathname: string): BreadcrumbItem[] {
|
|
||||||
const menuPath = findMenuPath(MAIN_DRAWER_LINKS, pathname);
|
|
||||||
|
|
||||||
if (!menuPath) return [];
|
|
||||||
|
|
||||||
return menuPath.map((menu, index) => {
|
|
||||||
const isLast = index === menuPath.length - 1;
|
|
||||||
|
|
||||||
return {
|
|
||||||
label: menu.text,
|
|
||||||
href: isLast ? menu.link : undefined,
|
|
||||||
isActive: isLast,
|
|
||||||
icon: menu.icon ? (
|
|
||||||
<Icon icon={menu.icon} width={16} height={16} />
|
|
||||||
) : undefined,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const EllipsisDropdown = ({
|
|
||||||
hiddenItems,
|
|
||||||
}: {
|
|
||||||
hiddenItems: BreadcrumbItem[];
|
|
||||||
}) => {
|
|
||||||
const dropdownId = useId();
|
|
||||||
const anchorId = useId();
|
|
||||||
|
|
||||||
return (
|
|
||||||
<li>
|
|
||||||
{/* Ellipsis Button */}
|
|
||||||
<Button
|
|
||||||
popoverTarget={dropdownId}
|
|
||||||
variant='ghost'
|
|
||||||
color='none'
|
|
||||||
style={
|
|
||||||
{
|
|
||||||
anchorName: `--breadcrumb-ellipsis-anchor-${anchorId}`,
|
|
||||||
} as React.CSSProperties
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<Icon icon='material-symbols:more-horiz' width={16} height={16} />
|
|
||||||
</Button>
|
|
||||||
|
|
||||||
{/* Dropdown Menu using popover API */}
|
|
||||||
<ul
|
|
||||||
className='dropdown menu rounded-box bg-base-100 border border-base-300 shadow-lg z-[9999] [&_a:hover]:no-underline [&_a:focus]:no-underline [&&]:no-underline [&&_a]:no-underline [&&]:hover:no-underline [&&]:flex [&&]:items-start [&&]:justify-start w-max'
|
|
||||||
popover='auto'
|
|
||||||
id={dropdownId}
|
|
||||||
style={
|
|
||||||
{
|
|
||||||
positionAnchor: `--breadcrumb-ellipsis-anchor-${anchorId}`,
|
|
||||||
} as React.CSSProperties
|
|
||||||
}
|
|
||||||
>
|
|
||||||
{hiddenItems.map((item, index) => {
|
|
||||||
const itemStyles = cn(
|
|
||||||
'[&]:flex [&]:items-center [&]:justify-start py-1 text-sm',
|
|
||||||
// Disabled state
|
|
||||||
item.isDisabled && 'text-base-content/40 opacity-50',
|
|
||||||
// Active/Last state
|
|
||||||
(item.isActive || item.isDisabled) && 'text-primary',
|
|
||||||
// Regular clickable state
|
|
||||||
!item.isDisabled && 'text-base-content/50'
|
|
||||||
);
|
|
||||||
|
|
||||||
const itemContent = (
|
|
||||||
<div className={itemStyles}>
|
|
||||||
{item.icon && (
|
|
||||||
<span className='inline-flex mr-2'>{item.icon}</span>
|
|
||||||
)}
|
|
||||||
{item.label}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<li
|
|
||||||
key={`ellipsis-${index}`}
|
|
||||||
className='[&&]:text-left [&&]:block w-full'
|
|
||||||
>
|
|
||||||
{item.href && !item.isDisabled ? (
|
|
||||||
<Link
|
|
||||||
href={item.href}
|
|
||||||
className='block !no-underline [&&]:text-left w-full'
|
|
||||||
onClick={(e) => e.stopPropagation()}
|
|
||||||
>
|
|
||||||
{itemContent}
|
|
||||||
</Link>
|
|
||||||
) : (
|
|
||||||
<div className='block !no-underline [&&]:cursor-default [&&]:hover:cursor-default [&&]:hover:bg-base-100 [&&]:text-left'>
|
|
||||||
{itemContent}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</li>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const Breadcrumb = ({
|
|
||||||
items,
|
|
||||||
size = 'md',
|
|
||||||
maxVisibleItems = 3,
|
|
||||||
showEllipsisDropdown = true,
|
|
||||||
className,
|
|
||||||
...props
|
|
||||||
}: BreadcrumbsProps) => {
|
|
||||||
const sizeClasses = {
|
|
||||||
xs: 'text-xs',
|
|
||||||
sm: 'text-sm',
|
|
||||||
md: 'text-base',
|
|
||||||
lg: 'text-lg',
|
|
||||||
xl: 'text-xl',
|
|
||||||
};
|
|
||||||
|
|
||||||
const getItemStyles = (
|
|
||||||
item: BreadcrumbItem,
|
|
||||||
position: 'first' | 'middle' | 'last' = 'middle'
|
|
||||||
) => {
|
|
||||||
const baseClasses = 'inline-flex items-center gap-2';
|
|
||||||
|
|
||||||
// Disabled state
|
|
||||||
if (item.isDisabled) {
|
|
||||||
return `${baseClasses} text-base-content/40 !cursor-default opacity-50 hover:!no-underline`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Active/Last state (no underline)
|
|
||||||
if (item.isActive || position === 'last') {
|
|
||||||
return `${baseClasses} text-primary !cursor-pointer hover:!no-underline`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Regular clickable state
|
|
||||||
return `${baseClasses} text-base-content/60`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderItem = (
|
|
||||||
item: BreadcrumbItem,
|
|
||||||
position: 'first' | 'middle' | 'last' = 'middle'
|
|
||||||
) => {
|
|
||||||
const styles = getItemStyles(item, position);
|
|
||||||
|
|
||||||
// Disabled items
|
|
||||||
if (item.isDisabled) {
|
|
||||||
return (
|
|
||||||
<span className={styles}>
|
|
||||||
{item.icon && item.icon}
|
|
||||||
{item.label}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Active/Last items
|
|
||||||
if (item.isActive || position === 'last') {
|
|
||||||
if (item.href) {
|
|
||||||
return (
|
|
||||||
<Link href={item.href} className={styles}>
|
|
||||||
{item.icon && (
|
|
||||||
<span className='inline-flex gap-2'>{item.icon}</span>
|
|
||||||
)}
|
|
||||||
{item.label}
|
|
||||||
</Link>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<span className={styles}>
|
|
||||||
{item.icon && item.icon}
|
|
||||||
{item.label}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Regular items
|
|
||||||
if (item.href) {
|
|
||||||
return (
|
|
||||||
<Link href={item.href} className={styles}>
|
|
||||||
{item.icon && <span className='inline-flex gap-2'>{item.icon}</span>}
|
|
||||||
{item.label}
|
|
||||||
</Link>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<span className={styles}>
|
|
||||||
{item.icon && item.icon}
|
|
||||||
{item.label}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderBreadcrumbList = () => {
|
|
||||||
// Show all items if within limit
|
|
||||||
if (items.length <= maxVisibleItems) {
|
|
||||||
return items.map((item, index) => {
|
|
||||||
const position =
|
|
||||||
index === 0
|
|
||||||
? 'first'
|
|
||||||
: index === items.length - 1
|
|
||||||
? 'last'
|
|
||||||
: 'middle';
|
|
||||||
return <li key={index}>{renderItem(item, position)}</li>;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collapsed items indexing when exceeding limit
|
|
||||||
const firstItem = items[0];
|
|
||||||
const lastItem = items[items.length - 1];
|
|
||||||
const visibleMiddleItems = items.slice(1, -1).slice(-(maxVisibleItems - 2));
|
|
||||||
const hiddenItems = items.slice(1, -1).slice(0, -(maxVisibleItems - 2));
|
|
||||||
const showEllipsis = showEllipsisDropdown && hiddenItems.length > 0;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<li>{renderItem(firstItem, 'first')}</li>
|
|
||||||
|
|
||||||
{/* Ellipsis for hidden items with dropdown */}
|
|
||||||
{showEllipsis && <EllipsisDropdown hiddenItems={hiddenItems} />}
|
|
||||||
|
|
||||||
{/* Middle items */}
|
|
||||||
{visibleMiddleItems.map((item, index) => (
|
|
||||||
<li key={`middle-${index}`}>{renderItem(item, 'middle')}</li>
|
|
||||||
))}
|
|
||||||
|
|
||||||
<li>{renderItem(lastItem, 'last')}</li>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<nav
|
|
||||||
aria-label='Breadcrumb'
|
|
||||||
className={cn('breadcrumbs', sizeClasses[size], className)}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<ul className='text-sm'>{renderBreadcrumbList()}</ul>
|
|
||||||
</nav>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Breadcrumb;
|
|
||||||
@@ -2,12 +2,11 @@ import react from 'react';
|
|||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { cn } from '@/lib/helper';
|
import { cn } from '@/lib/helper';
|
||||||
import { Color } from '@/types/theme';
|
import { Color } from '@/types/theme';
|
||||||
import { UrlObject } from 'url';
|
|
||||||
|
|
||||||
export interface ButtonProps extends react.ComponentProps<'button'> {
|
export interface ButtonProps extends react.ComponentProps<'button'> {
|
||||||
variant?: 'soft' | 'outline' | 'dash' | 'ghost' | 'link' | 'active';
|
variant?: 'soft' | 'outline' | 'dash' | 'ghost' | 'link' | 'active';
|
||||||
color?: Color;
|
color?: Color;
|
||||||
href?: string | UrlObject;
|
href?: string;
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
target?: string;
|
target?: string;
|
||||||
rel?: string;
|
rel?: string;
|
||||||
|
|||||||
+3
-17
@@ -22,7 +22,6 @@ export interface CardProps
|
|||||||
onCollapsedChange?: (collapsed: boolean) => void;
|
onCollapsedChange?: (collapsed: boolean) => void;
|
||||||
className?: {
|
className?: {
|
||||||
wrapper?: string;
|
wrapper?: string;
|
||||||
wrapperContent?: string;
|
|
||||||
image?: string;
|
image?: string;
|
||||||
body?: string;
|
body?: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
@@ -123,10 +122,6 @@ const Card = ({
|
|||||||
return cn(baseClasses, 'p-6', className?.body);
|
return cn(baseClasses, 'p-6', className?.body);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getCollapsibleClasses = () => {
|
|
||||||
return cn('', className?.collapsible);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getTitleClasses = () => {
|
const getTitleClasses = () => {
|
||||||
const sizeClasses = {
|
const sizeClasses = {
|
||||||
sm: 'text-lg',
|
sm: 'text-lg',
|
||||||
@@ -149,19 +144,11 @@ const Card = ({
|
|||||||
return cn('border-t border-base-300 mt-4 pt-4', className?.footer);
|
return cn('border-t border-base-300 mt-4 pt-4', className?.footer);
|
||||||
};
|
};
|
||||||
|
|
||||||
const getWrapperContentClasses = () => {
|
|
||||||
return cn('space-y-4', className?.wrapperContent);
|
|
||||||
};
|
|
||||||
|
|
||||||
const renderCardContent = () => {
|
const renderCardContent = () => {
|
||||||
const hasContent = children || actions || footer;
|
const hasContent = children || actions || footer;
|
||||||
|
|
||||||
const titleContent = (
|
const titleContent = (
|
||||||
<div
|
<div className='group flex items-center !justify-between w-full'>
|
||||||
className={
|
|
||||||
`group flex items-center justify-between! w-full` + getTitleClasses()
|
|
||||||
}
|
|
||||||
>
|
|
||||||
<div className='flex-1'>
|
<div className='flex-1'>
|
||||||
{title && <h2 className={getTitleClasses()}>{title}</h2>}
|
{title && <h2 className={getTitleClasses()}>{title}</h2>}
|
||||||
{subtitle && <p className={getSubtitleClasses()}>{subtitle}</p>}
|
{subtitle && <p className={getSubtitleClasses()}>{subtitle}</p>}
|
||||||
@@ -169,7 +156,7 @@ const Card = ({
|
|||||||
{collapsible && (
|
{collapsible && (
|
||||||
<button
|
<button
|
||||||
onClick={() => handleCollapsedChange(!isCollapsed)}
|
onClick={() => handleCollapsedChange(!isCollapsed)}
|
||||||
className={`btn btn-ghost btn-sm btn-circle` + getTitleClasses()}
|
className='btn btn-ghost btn-sm btn-circle'
|
||||||
aria-label={isCollapsed ? 'Expand content' : 'Collapse content'}
|
aria-label={isCollapsed ? 'Expand content' : 'Collapse content'}
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
@@ -186,7 +173,7 @@ const Card = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
const cardContent = (
|
const cardContent = (
|
||||||
<div className={getWrapperContentClasses()}>
|
<div className='space-y-4'>
|
||||||
{children}
|
{children}
|
||||||
{actions && <div className={getActionsClasses()}>{actions}</div>}
|
{actions && <div className={getActionsClasses()}>{actions}</div>}
|
||||||
{footer && <div className={getFooterClasses()}>{footer}</div>}
|
{footer && <div className={getFooterClasses()}>{footer}</div>}
|
||||||
@@ -217,7 +204,6 @@ const Card = ({
|
|||||||
titleClassName='w-full cursor-pointer'
|
titleClassName='w-full cursor-pointer'
|
||||||
contentClassName='p-0'
|
contentClassName='p-0'
|
||||||
fullWidth={true}
|
fullWidth={true}
|
||||||
className={getCollapsibleClasses()}
|
|
||||||
>
|
>
|
||||||
{cardContent}
|
{cardContent}
|
||||||
</Collapse>
|
</Collapse>
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ interface DrawerProps {
|
|||||||
className?: DrawerClassName;
|
className?: DrawerClassName;
|
||||||
onBackdropClick?: () => void;
|
onBackdropClick?: () => void;
|
||||||
closeOnBackdropClick?: boolean;
|
closeOnBackdropClick?: boolean;
|
||||||
expandedContent?: ReactNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type DrawerClassName = {
|
type DrawerClassName = {
|
||||||
@@ -24,7 +23,6 @@ type DrawerClassName = {
|
|||||||
drawerSide?: string;
|
drawerSide?: string;
|
||||||
drawerOverlay?: string;
|
drawerOverlay?: string;
|
||||||
drawerSidebarContent?: string;
|
drawerSidebarContent?: string;
|
||||||
drawerExpandedContent?: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const Drawer = ({
|
const Drawer = ({
|
||||||
@@ -38,7 +36,6 @@ const Drawer = ({
|
|||||||
className,
|
className,
|
||||||
onBackdropClick,
|
onBackdropClick,
|
||||||
closeOnBackdropClick = true,
|
closeOnBackdropClick = true,
|
||||||
expandedContent,
|
|
||||||
}: DrawerProps) => {
|
}: DrawerProps) => {
|
||||||
const getDrawerClassNames = (): DrawerClassName => {
|
const getDrawerClassNames = (): DrawerClassName => {
|
||||||
const baseClassNames = {
|
const baseClassNames = {
|
||||||
@@ -49,24 +46,12 @@ const Drawer = ({
|
|||||||
drawerSidebarContent: 'min-h-full bg-base-100',
|
drawerSidebarContent: 'min-h-full bg-base-100',
|
||||||
};
|
};
|
||||||
|
|
||||||
const getSidebarWidth = () => {
|
|
||||||
if (variant === 'sidebar') {
|
|
||||||
return expandedContent
|
|
||||||
? 'w-full lg:min-w-[600px] lg:max-w-[600px]'
|
|
||||||
: 'w-full max-w-[300px] lg:w-[300px]';
|
|
||||||
}
|
|
||||||
if (className?.drawerSidebarContent) {
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
return 'w-full sm:min-w-120 sm:w-fit';
|
|
||||||
};
|
|
||||||
|
|
||||||
if (variant === 'sidebar') {
|
if (variant === 'sidebar') {
|
||||||
return {
|
return {
|
||||||
...baseClassNames,
|
...baseClassNames,
|
||||||
drawerSidebarContent: cn(
|
drawerSidebarContent: cn(
|
||||||
baseClassNames.drawerSidebarContent,
|
baseClassNames.drawerSidebarContent,
|
||||||
getSidebarWidth()
|
'w-full max-w-[300px] lg:w-[300px]'
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
} else if (variant === 'right') {
|
} else if (variant === 'right') {
|
||||||
@@ -75,11 +60,11 @@ const Drawer = ({
|
|||||||
drawer: cn(baseClassNames.drawer, 'drawer-end'),
|
drawer: cn(baseClassNames.drawer, 'drawer-end'),
|
||||||
drawerSide: cn(
|
drawerSide: cn(
|
||||||
baseClassNames.drawerSide,
|
baseClassNames.drawerSide,
|
||||||
'border-l border-solid border-gray-200 sm:drawer-side w-screen top-0 right-0 fixed z-21'
|
'border-l border-solid border-gray-200 drawer-side w-screen top-0 right-0 fixed z-21'
|
||||||
),
|
),
|
||||||
drawerSidebarContent: cn(
|
drawerSidebarContent: cn(
|
||||||
baseClassNames.drawerSidebarContent,
|
baseClassNames.drawerSidebarContent,
|
||||||
getSidebarWidth()
|
'w-full min-w-120 sm:w-fit'
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
} else if (variant === 'left') {
|
} else if (variant === 'left') {
|
||||||
@@ -91,7 +76,7 @@ const Drawer = ({
|
|||||||
),
|
),
|
||||||
drawerSidebarContent: cn(
|
drawerSidebarContent: cn(
|
||||||
baseClassNames.drawerSidebarContent,
|
baseClassNames.drawerSidebarContent,
|
||||||
getSidebarWidth()
|
'w-full min-w-120 sm:w-fit'
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -153,38 +138,15 @@ const Drawer = ({
|
|||||||
onClick={closeDrawer}
|
onClick={closeDrawer}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{/* Sidebar Content - Full height container */}
|
{/* Sidebar Content */}
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'flex h-screen bg-base-100 overflow-hidden',
|
|
||||||
variant === 'right' && 'flex-row'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{/* Primary Sidebar Content */}
|
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
varianClassName?.drawerSidebarContent,
|
varianClassName?.drawerSidebarContent,
|
||||||
className?.drawerSidebarContent,
|
className?.drawerContent
|
||||||
'overflow-y-auto'
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{sidebarContent}
|
{sidebarContent}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Expanded Drawer (Right side, side-by-side) */}
|
|
||||||
{expandedContent && (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'border-l border-gray-200 bg-white flex flex-col h-full',
|
|
||||||
className?.drawerExpandedContent
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className='overflow-y-auto flex-1 h-full'>
|
|
||||||
{expandedContent}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,114 +0,0 @@
|
|||||||
import React, { ReactNode, useState, useRef } from 'react';
|
|
||||||
|
|
||||||
import { cn } from '@/lib/helper';
|
|
||||||
|
|
||||||
export interface DropdownProps {
|
|
||||||
trigger: ReactNode;
|
|
||||||
children: ReactNode;
|
|
||||||
className?: {
|
|
||||||
wrapper?: string;
|
|
||||||
trigger?: string;
|
|
||||||
content?: string;
|
|
||||||
};
|
|
||||||
align?: 'start' | 'center' | 'end';
|
|
||||||
direction?: 'top' | 'bottom' | 'left' | 'right';
|
|
||||||
hover?: boolean;
|
|
||||||
defaultOpen?: boolean;
|
|
||||||
open?: boolean;
|
|
||||||
close?: boolean;
|
|
||||||
controlled?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const Dropdown = ({
|
|
||||||
trigger,
|
|
||||||
children,
|
|
||||||
className,
|
|
||||||
align,
|
|
||||||
direction,
|
|
||||||
hover,
|
|
||||||
defaultOpen = false,
|
|
||||||
open,
|
|
||||||
close,
|
|
||||||
controlled = false,
|
|
||||||
}: DropdownProps) => {
|
|
||||||
const [isOpen, setIsOpen] = useState(defaultOpen);
|
|
||||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
||||||
|
|
||||||
const toggleDropdown = () => {
|
|
||||||
if (!controlled) {
|
|
||||||
const newState = !isOpen;
|
|
||||||
setIsOpen(newState);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getWrapperClasses = () => {
|
|
||||||
const openState = controlled ? open : isOpen;
|
|
||||||
|
|
||||||
return cn(
|
|
||||||
'dropdown',
|
|
||||||
{
|
|
||||||
'dropdown-start': align === 'start',
|
|
||||||
'dropdown-center': align === 'center',
|
|
||||||
'dropdown-end': align === 'end',
|
|
||||||
'dropdown-top': direction === 'top',
|
|
||||||
'dropdown-bottom': direction === 'bottom',
|
|
||||||
'dropdown-left': direction === 'left',
|
|
||||||
'dropdown-right': direction === 'right',
|
|
||||||
'dropdown-hover': hover,
|
|
||||||
'dropdown-open': openState && !close,
|
|
||||||
'dropdown-close': close,
|
|
||||||
},
|
|
||||||
className?.wrapper
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getTriggerClasses = () => {
|
|
||||||
return cn(className?.trigger);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getContentClasses = () => {
|
|
||||||
return cn(
|
|
||||||
'dropdown-content z-[9999] shadow-sm bg-base-100 rounded-box',
|
|
||||||
className?.content
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (controlled) {
|
|
||||||
return (
|
|
||||||
<div className={getWrapperClasses()}>
|
|
||||||
{trigger}
|
|
||||||
{open && !close && (
|
|
||||||
<div tabIndex={-1} className={getContentClasses()}>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div ref={dropdownRef} className={getWrapperClasses()}>
|
|
||||||
<div
|
|
||||||
tabIndex={0}
|
|
||||||
role='button'
|
|
||||||
className={getTriggerClasses()}
|
|
||||||
onClick={toggleDropdown}
|
|
||||||
onKeyDown={(e) => {
|
|
||||||
if (e.key === 'Enter' || e.key === ' ') {
|
|
||||||
e.preventDefault();
|
|
||||||
toggleDropdown();
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{trigger}
|
|
||||||
</div>
|
|
||||||
{!close && (
|
|
||||||
<div tabIndex={-1} className={getContentClasses()}>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Dropdown;
|
|
||||||
@@ -5,8 +5,6 @@ import Tooltip from '@/components/Tooltip';
|
|||||||
import { cn } from '@/lib/helper';
|
import { cn } from '@/lib/helper';
|
||||||
import { Icon } from '@iconify/react';
|
import { Icon } from '@iconify/react';
|
||||||
|
|
||||||
import { useAuth } from '@/services/hooks/useAuth';
|
|
||||||
|
|
||||||
type FloatingActionsButtonProps = {
|
type FloatingActionsButtonProps = {
|
||||||
actions: {
|
actions: {
|
||||||
action: 'DETAIL' | 'EDIT' | 'DELETE';
|
action: 'DETAIL' | 'EDIT' | 'DELETE';
|
||||||
@@ -15,7 +13,6 @@ type FloatingActionsButtonProps = {
|
|||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
permissions?: string | string[];
|
|
||||||
}[];
|
}[];
|
||||||
approvals: {
|
approvals: {
|
||||||
action: 'APPROVED' | 'REJECTED';
|
action: 'APPROVED' | 'REJECTED';
|
||||||
@@ -23,7 +20,6 @@ type FloatingActionsButtonProps = {
|
|||||||
label?: string;
|
label?: string;
|
||||||
onClick?: () => void;
|
onClick?: () => void;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
permissions?: string | string[];
|
|
||||||
}[];
|
}[];
|
||||||
selectedRowIds: number[];
|
selectedRowIds: number[];
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
@@ -35,12 +31,9 @@ const FloatingActionsButton = ({
|
|||||||
selectedRowIds,
|
selectedRowIds,
|
||||||
onClose,
|
onClose,
|
||||||
}: FloatingActionsButtonProps) => {
|
}: FloatingActionsButtonProps) => {
|
||||||
const { permissionCheck } = useAuth();
|
|
||||||
// Jika tidak ada baris yang dipilih, jangan tampilkan FAB
|
// Jika tidak ada baris yang dipilih, jangan tampilkan FAB
|
||||||
const positionStyles =
|
const positionStyles =
|
||||||
selectedRowIds.length > 0
|
selectedRowIds.length > 0 ? 'bottom-[10%]' : 'bottom-[-100%]';
|
||||||
? 'bottom-[5%] opacity-100'
|
|
||||||
: 'bottom-[-5%] opacity-0';
|
|
||||||
|
|
||||||
// Helper untuk menentukan gaya warna tombol approval
|
// Helper untuk menentukan gaya warna tombol approval
|
||||||
const getApprovalColor = (action: 'APPROVED' | 'REJECTED') => {
|
const getApprovalColor = (action: 'APPROVED' | 'REJECTED') => {
|
||||||
@@ -60,7 +53,7 @@ const FloatingActionsButton = ({
|
|||||||
// Container utama FAB
|
// Container utama FAB
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
`fixed ${positionStyles} inset-x-1/2 -translate-x-1/2 z-50`,
|
`absolute ${positionStyles} inset-x-1/2 -translate-x-1/2 z-50`,
|
||||||
'mx-auto w-full max-w-sm sm:mx-0 bg-base-300 p-4 rounded-xl shadow-md transition-all duration-300 transform',
|
'mx-auto w-full max-w-sm sm:mx-0 bg-base-300 p-4 rounded-xl shadow-md transition-all duration-300 transform',
|
||||||
'bg-slate-950 backdrop-blur-md'
|
'bg-slate-950 backdrop-blur-md'
|
||||||
)}
|
)}
|
||||||
@@ -76,18 +69,7 @@ const FloatingActionsButton = ({
|
|||||||
<div className='flex gap-4 items-center'>
|
<div className='flex gap-4 items-center'>
|
||||||
{/* Render Aksi dari props.actions */}
|
{/* Render Aksi dari props.actions */}
|
||||||
{actions
|
{actions
|
||||||
.filter((action) => {
|
.filter((action) => !action.hidden)
|
||||||
if (action.hidden) return false;
|
|
||||||
if (action.permissions) {
|
|
||||||
if (typeof action.permissions === 'string') {
|
|
||||||
return permissionCheck(action.permissions);
|
|
||||||
}
|
|
||||||
return action.permissions.some((permission) =>
|
|
||||||
permissionCheck(permission)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
.map((action, index) => {
|
.map((action, index) => {
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
@@ -127,19 +109,7 @@ const FloatingActionsButton = ({
|
|||||||
|
|
||||||
{/* === BARIS BAWAH: Approval Buttons (Approve/Reject) === */}
|
{/* === BARIS BAWAH: Approval Buttons (Approve/Reject) === */}
|
||||||
<div className={`grid grid-cols-${approvals.length} gap-3`}>
|
<div className={`grid grid-cols-${approvals.length} gap-3`}>
|
||||||
{approvals
|
{approvals.map((approval, index) => (
|
||||||
.filter((approval) => {
|
|
||||||
if (approval.permissions) {
|
|
||||||
if (typeof approval.permissions === 'string') {
|
|
||||||
return permissionCheck(approval.permissions);
|
|
||||||
}
|
|
||||||
return approval.permissions.some((permission) =>
|
|
||||||
permissionCheck(permission)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
.map((approval, index) => (
|
|
||||||
<Button
|
<Button
|
||||||
key={index}
|
key={index}
|
||||||
onClick={approval.onClick}
|
onClick={approval.onClick}
|
||||||
|
|||||||
@@ -9,13 +9,10 @@ import Drawer from '@/components/Drawer';
|
|||||||
import Navbar from '@/components/Navbar';
|
import Navbar from '@/components/Navbar';
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import SidebarMenu from '@/components/molecules/SidebarMenu';
|
import SidebarMenu from '@/components/molecules/SidebarMenu';
|
||||||
import PermissionNotFound from '@/components/helper/PermissionNotFound';
|
|
||||||
|
|
||||||
import { useUiStore } from '@/stores/ui/ui.store';
|
import { useUiStore } from '@/stores/ui/ui.store';
|
||||||
import { MAIN_DRAWER_LINKS } from '@/config/constant';
|
import { MAIN_DRAWER_LINKS } from '@/config/constant';
|
||||||
import { isPathActive } from '@/lib/helper';
|
import { isPathActive } from '@/lib/helper';
|
||||||
import { ROUTE_PERMISSIONS } from '@/config/route-permission';
|
|
||||||
import { useAuth } from '@/services/hooks/useAuth';
|
|
||||||
|
|
||||||
const MainDrawerContent = () => {
|
const MainDrawerContent = () => {
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
@@ -26,34 +23,29 @@ const MainDrawerContent = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='w-full flex flex-col'>
|
<div className='w-full p-4 flex flex-col gap-4'>
|
||||||
<div className='p-3 flex flex-row items-center gap-4 border-b border-base-content/10'>
|
<div className='flex flex-row items-center gap-4'>
|
||||||
<div className='flex flex-row items-center gap-2'>
|
|
||||||
<Image
|
<Image
|
||||||
src='/assets/img/lti-logo.png'
|
src='/assets/img/lti-logo.png'
|
||||||
alt='LTI Logo'
|
alt='MBU Logo'
|
||||||
width={40}
|
width={256}
|
||||||
height={40}
|
height={256}
|
||||||
className='w-full max-w-10 h-auto'
|
className='w-full max-w-16 h-auto'
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div className='font-roboto'>
|
<h1 className='text-xl font-bold'>LTI ERP</h1>
|
||||||
<h1 className='text-sm font-semibold'>LTI ERP</h1>
|
|
||||||
<p className='text-sm text-black/50'>Lumbung Telur Indonesia</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className='grow flex flex-row justify-end sm:hidden'>
|
<div className='grow flex flex-row justify-end sm:hidden'>
|
||||||
<Button
|
<Button
|
||||||
variant='soft'
|
variant='soft'
|
||||||
color='error'
|
color='error'
|
||||||
onClick={closeMainDrawerHandler}
|
onClick={closeMainDrawerHandler}
|
||||||
className='p-1 rounded-full'
|
className='rounded-full'
|
||||||
>
|
>
|
||||||
<Icon
|
<Icon
|
||||||
icon='material-symbols:close-rounded'
|
icon='material-symbols:close-rounded'
|
||||||
width={16}
|
width={24}
|
||||||
height={16}
|
height={24}
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
@@ -70,41 +62,54 @@ const MainDrawer = ({
|
|||||||
}>) => {
|
}>) => {
|
||||||
const { mainDrawerOpen, setMainDrawerOpen } = useUiStore();
|
const { mainDrawerOpen, setMainDrawerOpen } = useUiStore();
|
||||||
const pathname = usePathname();
|
const pathname = usePathname();
|
||||||
const { permissionCheck } = useAuth();
|
|
||||||
|
|
||||||
const formattedPathname = pathname.endsWith('/') ? pathname : `${pathname}/`;
|
const getPageTitle = useCallback(() => {
|
||||||
|
let title = '';
|
||||||
|
|
||||||
const isPathnameNotFoundPage = formattedPathname === '/404/';
|
const activeMenu = MAIN_DRAWER_LINKS.find((item) =>
|
||||||
|
isPathActive(pathname, item.link)
|
||||||
const isPermitted = ROUTE_PERMISSIONS[formattedPathname]?.some((permission) =>
|
|
||||||
permissionCheck(permission)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const traverseMenuTitle = (menu: typeof activeMenu) => {
|
||||||
|
if (!menu) return;
|
||||||
|
|
||||||
|
const hasSubmenu = menu?.submenu && menu?.submenu.length > 0;
|
||||||
|
|
||||||
|
if (!title) {
|
||||||
|
title += menu?.text;
|
||||||
|
} else {
|
||||||
|
title += ' - ' + menu?.text;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hasSubmenu || !menu.submenu) return;
|
||||||
|
|
||||||
|
const activeSubmenu = menu.submenu?.find((item) =>
|
||||||
|
isPathActive(pathname, item.link)
|
||||||
|
);
|
||||||
|
|
||||||
|
traverseMenuTitle(activeSubmenu);
|
||||||
|
};
|
||||||
|
|
||||||
|
traverseMenuTitle(activeMenu);
|
||||||
|
|
||||||
|
return title;
|
||||||
|
}, [pathname]);
|
||||||
|
|
||||||
|
const pageTitle = getPageTitle();
|
||||||
|
|
||||||
const toggleSidebar = () => {
|
const toggleSidebar = () => {
|
||||||
setMainDrawerOpen(!mainDrawerOpen);
|
setMainDrawerOpen(!mainDrawerOpen);
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!isPermitted && !isPathnameNotFoundPage) {
|
|
||||||
return <PermissionNotFound />;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isPathnameNotFoundPage) {
|
|
||||||
return children;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Drawer
|
<Drawer
|
||||||
open={mainDrawerOpen}
|
open={mainDrawerOpen}
|
||||||
setOpen={setMainDrawerOpen}
|
setOpen={setMainDrawerOpen}
|
||||||
openOnLarge
|
openOnLarge
|
||||||
sidebarContent={<MainDrawerContent />}
|
sidebarContent={<MainDrawerContent />}
|
||||||
className={{
|
|
||||||
drawerSide: 'border-r border-base-content/10',
|
|
||||||
drawerSidebarContent: 'min-w-[244px] lg:w-[244px]',
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<main className='w-full h-full flex flex-col'>
|
<main className='w-full h-full flex flex-col'>
|
||||||
<Navbar toggleSidebar={toggleSidebar} />
|
<Navbar title={pageTitle as string} toggleSidebar={toggleSidebar} />
|
||||||
|
|
||||||
{children}
|
{children}
|
||||||
</main>
|
</main>
|
||||||
|
|||||||
@@ -53,25 +53,15 @@ interface ModalProps {
|
|||||||
ref: RefObject<HTMLDialogElement | null>;
|
ref: RefObject<HTMLDialogElement | null>;
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
closeOnBackdrop?: boolean;
|
closeOnBackdrop?: boolean;
|
||||||
onBackdropClick?: () => void;
|
|
||||||
position?: 'top' | 'middle' | 'bottom' | 'start' | 'end';
|
|
||||||
className?: {
|
className?: {
|
||||||
modal?: string;
|
modal?: string;
|
||||||
modalBox?: string;
|
modalBox?: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const Modal = ({
|
const Modal = ({ ref, children, closeOnBackdrop, className }: ModalProps) => {
|
||||||
ref,
|
|
||||||
children,
|
|
||||||
closeOnBackdrop,
|
|
||||||
onBackdropClick,
|
|
||||||
position = 'middle',
|
|
||||||
className,
|
|
||||||
}: ModalProps) => {
|
|
||||||
const handleBackdropClick = (e: React.MouseEvent<HTMLDialogElement>) => {
|
const handleBackdropClick = (e: React.MouseEvent<HTMLDialogElement>) => {
|
||||||
if (closeOnBackdrop && e.target === ref.current) {
|
if (closeOnBackdrop && e.target === ref.current) {
|
||||||
onBackdropClick?.();
|
|
||||||
ref.current?.close();
|
ref.current?.close();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -79,17 +69,7 @@ const Modal = ({
|
|||||||
return (
|
return (
|
||||||
<dialog
|
<dialog
|
||||||
ref={ref}
|
ref={ref}
|
||||||
className={cn(
|
className={cn('modal', className?.modal)}
|
||||||
'modal',
|
|
||||||
{
|
|
||||||
'modal-top': position === 'top',
|
|
||||||
'modal-middle': position === 'middle',
|
|
||||||
'modal-bottom': position === 'bottom',
|
|
||||||
'modal-start': position === 'start',
|
|
||||||
'modal-end': position === 'end',
|
|
||||||
},
|
|
||||||
className?.modal
|
|
||||||
)}
|
|
||||||
onClick={handleBackdropClick}
|
onClick={handleBackdropClick}
|
||||||
>
|
>
|
||||||
<div className={cn('modal-box', className?.modalBox)}>{children}</div>
|
<div className={cn('modal-box', className?.modalBox)}>{children}</div>
|
||||||
|
|||||||
+29
-46
@@ -1,28 +1,26 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import toast from 'react-hot-toast';
|
import toast from 'react-hot-toast';
|
||||||
import { usePathname, useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
import { Icon } from '@iconify/react';
|
import { Icon } from '@iconify/react';
|
||||||
|
import Menu from '@/components/menu/Menu';
|
||||||
|
import MenuItem from '@/components/menu/MenuItem';
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import Breadcrumb, { buildBreadcrumbs } from '@/components/Breadcrumb';
|
import Dropdown from '@/components/dropdown/Dropdown';
|
||||||
import PopoverButton from '@/components/popover/PopoverButton';
|
|
||||||
import PopoverContent from '@/components/popover/PopoverContent';
|
|
||||||
|
|
||||||
import { useAuth } from '@/services/hooks/useAuth';
|
import { useAuth } from '@/services/hooks/useAuth';
|
||||||
import { AuthApi } from '@/services/api/auth';
|
import { AuthApi } from '@/services/api/auth';
|
||||||
import { isResponseError } from '@/lib/api-helper';
|
import { isResponseError } from '@/lib/api-helper';
|
||||||
import { useUiStore } from '@/stores/ui/ui.store';
|
|
||||||
|
|
||||||
interface NavbarProps {
|
interface NavbarProps {
|
||||||
|
title: string;
|
||||||
toggleSidebar?: () => void;
|
toggleSidebar?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Navbar = ({ toggleSidebar }: NavbarProps) => {
|
const Navbar = ({ title, toggleSidebar }: NavbarProps) => {
|
||||||
const { setUser } = useAuth();
|
const { setUser } = useAuth();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const pathname = usePathname();
|
|
||||||
const navbarActions = useUiStore((state) => state.navbarActions);
|
|
||||||
|
|
||||||
const logoutClickHandler = async () => {
|
const logoutClickHandler = async () => {
|
||||||
const logoutRes = await AuthApi.logout();
|
const logoutRes = await AuthApi.logout();
|
||||||
@@ -37,54 +35,39 @@ const Navbar = ({ toggleSidebar }: NavbarProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='navbar p-3 bg-base-100 border-b border-base-content/10'>
|
<div className='navbar px-4 bg-base-100 shadow-sm'>
|
||||||
<div className='flex-1'>
|
<div className='flex-1'>
|
||||||
<div className='flex flex-row items-center gap-4'>
|
<div className='flex flex-row items-center gap-4'>
|
||||||
{toggleSidebar && (
|
{toggleSidebar && (
|
||||||
<Button
|
<Button onClick={toggleSidebar} className='block lg:hidden'>
|
||||||
variant='ghost'
|
<Icon
|
||||||
color='none'
|
icon='material-symbols:menu-rounded'
|
||||||
onClick={toggleSidebar}
|
width={24}
|
||||||
className='block lg:hidden p-[9px] text-base-content/50 border border-base-content/10 rounded-xl shadow-button-soft'
|
height={24}
|
||||||
>
|
/>
|
||||||
<Icon icon='heroicons:bars-3' width={20} height={20} />
|
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Breadcrumb items={buildBreadcrumbs(pathname)} />
|
<span className='font-bold text-xl text-primary'>{title}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className='flex gap-2 items-center'>
|
<div className='flex gap-2'>
|
||||||
{/* Page-specific actions */}
|
<Dropdown
|
||||||
{navbarActions && <div className='mr-2'>{navbarActions}</div>}
|
position='bottom-end'
|
||||||
<PopoverButton
|
trigger={
|
||||||
tabIndex={0}
|
<div className='btn btn-ghost btn-circle avatar'>
|
||||||
variant='ghost'
|
<div className='w-10 rounded-full border flex justify-center items-center'>
|
||||||
color='none'
|
<Icon icon='uil:user' width={40} height={40} />
|
||||||
popoverTarget='accountNavbar'
|
</div>
|
||||||
anchorName='--account-navbar'
|
</div>
|
||||||
className='p-[9px] text-base-content/50 border border-base-content/10 rounded-xl shadow-button-soft'
|
}
|
||||||
|
contentClassName='w-52 mt-3'
|
||||||
>
|
>
|
||||||
<Icon icon='heroicons:user' width={20} height={20} />
|
<Menu className='p-2 bg-base-100 shadow rounded-box menu-sm'>
|
||||||
</PopoverButton>
|
<MenuItem title='Logout' onClick={logoutClickHandler} />
|
||||||
|
</Menu>
|
||||||
<PopoverContent
|
</Dropdown>
|
||||||
id='accountNavbar'
|
|
||||||
anchorName='--account-navbar'
|
|
||||||
position='bottom-start'
|
|
||||||
className='rounded-xl border border-base-content/5 shadow-sm'
|
|
||||||
>
|
|
||||||
<Button
|
|
||||||
onClick={logoutClickHandler}
|
|
||||||
variant='ghost'
|
|
||||||
color='error'
|
|
||||||
className='p-3 justify-start text-sm font-semibold w-full'
|
|
||||||
>
|
|
||||||
<Icon icon='heroicons-outline:logout' width={20} height={20} />
|
|
||||||
Logout
|
|
||||||
</Button>
|
|
||||||
</PopoverContent>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
+22
-171
@@ -1,12 +1,11 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { Fragment, ReactNode, useCallback, useEffect, useState } from 'react';
|
import { ReactNode, useCallback, useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
flexRender,
|
flexRender,
|
||||||
getCoreRowModel,
|
getCoreRowModel,
|
||||||
getFilteredRowModel,
|
getFilteredRowModel,
|
||||||
getPaginationRowModel,
|
getPaginationRowModel,
|
||||||
getExpandedRowModel,
|
|
||||||
getSortedRowModel,
|
getSortedRowModel,
|
||||||
TableOptions,
|
TableOptions,
|
||||||
useReactTable,
|
useReactTable,
|
||||||
@@ -16,7 +15,6 @@ import {
|
|||||||
OnChangeFn,
|
OnChangeFn,
|
||||||
Row,
|
Row,
|
||||||
HeaderContext,
|
HeaderContext,
|
||||||
ExpandedState,
|
|
||||||
} from '@tanstack/react-table';
|
} from '@tanstack/react-table';
|
||||||
import { rankItem } from '@tanstack/match-sorter-utils';
|
import { rankItem } from '@tanstack/match-sorter-utils';
|
||||||
import { Icon } from '@iconify/react';
|
import { Icon } from '@iconify/react';
|
||||||
@@ -33,16 +31,11 @@ interface TableClassNames {
|
|||||||
headerColumnClassName?: string;
|
headerColumnClassName?: string;
|
||||||
tableBodyClassName?: string;
|
tableBodyClassName?: string;
|
||||||
bodyRowClassName?: string;
|
bodyRowClassName?: string;
|
||||||
selectedBodyRowClassName?: string;
|
|
||||||
bodyColumnClassName?: string;
|
bodyColumnClassName?: string;
|
||||||
bodySubRowClassName?: (depth: number) => string;
|
|
||||||
selectedBodySubRowClassName?: (depth: number) => string;
|
|
||||||
bodySubRowColumnClassName?: (depth: number) => string;
|
|
||||||
tableFooterClassName?: string;
|
tableFooterClassName?: string;
|
||||||
footerRowClassName?: string;
|
footerRowClassName?: string;
|
||||||
footerColumnClassName?: string;
|
footerColumnClassName?: string;
|
||||||
paginationClassName?: string;
|
paginationClassName?: string;
|
||||||
skeletonCellClassName?: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TableProps<TData extends object> {
|
export interface TableProps<TData extends object> {
|
||||||
@@ -66,23 +59,10 @@ export interface TableProps<TData extends object> {
|
|||||||
enableRowSelection?: boolean | ((row: Row<TData>) => boolean);
|
enableRowSelection?: boolean | ((row: Row<TData>) => boolean);
|
||||||
renderFooter?: boolean;
|
renderFooter?: boolean;
|
||||||
withCheckbox?: boolean;
|
withCheckbox?: boolean;
|
||||||
withPagination?: boolean;
|
|
||||||
rowOptions?: number[];
|
rowOptions?: number[];
|
||||||
/**
|
|
||||||
* Custom row renderer. Should return a complete <tr> element or null.
|
|
||||||
* This gives full control over the row structure including colspan.
|
|
||||||
* Return null to render the default row.
|
|
||||||
*/
|
|
||||||
renderCustomRow?: (row: Row<TData>) => ReactNode | null;
|
|
||||||
getRowCanExpand?: (row: Row<TData>) => boolean;
|
|
||||||
renderSubComponent?: (props: { row: Row<TData> }) => React.ReactElement;
|
|
||||||
expanded?: ExpandedState;
|
|
||||||
getSubRows?: (originalRow: TData, index: number) => TData[] | undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const DUMMY_SKELETON_DATA = Array.from({ length: 10 }, (_, index) => ({
|
const DUMMY_SKELETON_DATA = [{}, {}, {}, {}, {}];
|
||||||
id: index,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const emptyContentDefaultValue = (
|
const emptyContentDefaultValue = (
|
||||||
<div className='w-full p-5 text-center'>
|
<div className='w-full p-5 text-center'>
|
||||||
@@ -100,18 +80,11 @@ export const TABLE_DEFAULT_STYLING = {
|
|||||||
tableHeaderClassName: '',
|
tableHeaderClassName: '',
|
||||||
headerRowClassName: '',
|
headerRowClassName: '',
|
||||||
headerColumnClassName:
|
headerColumnClassName:
|
||||||
'px-4 py-3 border-base-content/10 text-base-content/50 text-sm font-medium',
|
'px-4 py-3 border-base-content/10 text-base-content/50',
|
||||||
tableBodyClassName: '',
|
tableBodyClassName: '',
|
||||||
bodyRowClassName:
|
bodyRowClassName: 'border-t border-base-content/10',
|
||||||
'transition-all duration-200 border-t border-base-content/10 bg-transparent',
|
bodyColumnClassName: 'px-4 py-3 text-base-content',
|
||||||
selectedBodyRowClassName: 'bg-primary/5',
|
paginationClassName: '',
|
||||||
bodyColumnClassName: 'px-4 py-3 text-base-content font-medium',
|
|
||||||
bodySubRowClassName: (depth: number) =>
|
|
||||||
'transition-all duration-200 border-t border-base-content/10 bg-transparent',
|
|
||||||
selectedBodySubRowClassName: (depth: number) => 'bg-primary/5',
|
|
||||||
bodySubRowColumnClassName: (depth: number) =>
|
|
||||||
'px-4 py-3 text-base-content font-medium',
|
|
||||||
paginationClassName: 'px-3',
|
|
||||||
tableFooterClassName: 'font-semibold border-base-content/10',
|
tableFooterClassName: 'font-semibold border-base-content/10',
|
||||||
footerRowClassName: 'bg-base-200 border-t-2 border-base-content/10',
|
footerRowClassName: 'bg-base-200 border-t-2 border-base-content/10',
|
||||||
footerColumnClassName: 'p-4 text-base-content whitespace-nowrap',
|
footerColumnClassName: 'p-4 text-base-content whitespace-nowrap',
|
||||||
@@ -138,13 +111,7 @@ const Table = <TData extends object>({
|
|||||||
enableRowSelection,
|
enableRowSelection,
|
||||||
renderFooter = false,
|
renderFooter = false,
|
||||||
withCheckbox = false,
|
withCheckbox = false,
|
||||||
withPagination = true,
|
|
||||||
rowOptions = [10, 20, 50, 100],
|
rowOptions = [10, 20, 50, 100],
|
||||||
renderCustomRow,
|
|
||||||
getRowCanExpand,
|
|
||||||
renderSubComponent,
|
|
||||||
expanded = {},
|
|
||||||
getSubRows,
|
|
||||||
}: TableProps<TData>) => {
|
}: TableProps<TData>) => {
|
||||||
const isServerSideTable =
|
const isServerSideTable =
|
||||||
totalItems !== undefined &&
|
totalItems !== undefined &&
|
||||||
@@ -177,14 +144,10 @@ const Table = <TData extends object>({
|
|||||||
getSortedRowModel: getSortedRowModel(),
|
getSortedRowModel: getSortedRowModel(),
|
||||||
getPaginationRowModel: getPaginationRowModel(),
|
getPaginationRowModel: getPaginationRowModel(),
|
||||||
onPaginationChange: setPagination,
|
onPaginationChange: setPagination,
|
||||||
getExpandedRowModel: getExpandedRowModel(),
|
|
||||||
getRowCanExpand: getRowCanExpand ?? (getSubRows ? undefined : () => false),
|
|
||||||
getSubRows,
|
|
||||||
manualSorting,
|
manualSorting,
|
||||||
state: {
|
state: {
|
||||||
pagination,
|
pagination,
|
||||||
globalFilter: fuzzySearchValue,
|
globalFilter: fuzzySearchValue,
|
||||||
expanded,
|
|
||||||
},
|
},
|
||||||
filterFns: {
|
filterFns: {
|
||||||
fuzzy: fuzzyFilter,
|
fuzzy: fuzzyFilter,
|
||||||
@@ -252,40 +215,14 @@ const Table = <TData extends object>({
|
|||||||
}, [pageSize, setPageSize]);
|
}, [pageSize, setPageSize]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={tableClassNames.containerClassName}>
|
||||||
className={cn(
|
<div className={tableClassNames.tableWrapperClassName}>
|
||||||
TABLE_DEFAULT_STYLING.containerClassName,
|
<table className={tableClassNames.tableClassName}>
|
||||||
tableClassNames.containerClassName,
|
<thead className={tableClassNames.tableHeaderClassName}>
|
||||||
{
|
|
||||||
'mb-0': !withPagination,
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
TABLE_DEFAULT_STYLING.tableWrapperClassName,
|
|
||||||
tableClassNames.tableWrapperClassName
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<table
|
|
||||||
className={cn(
|
|
||||||
TABLE_DEFAULT_STYLING.tableClassName,
|
|
||||||
tableClassNames.tableClassName
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<thead
|
|
||||||
className={cn(
|
|
||||||
TABLE_DEFAULT_STYLING.tableHeaderClassName,
|
|
||||||
tableClassNames.tableHeaderClassName
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{table.getHeaderGroups().map((headerGroup) => (
|
{table.getHeaderGroups().map((headerGroup) => (
|
||||||
<tr
|
<tr
|
||||||
key={headerGroup.id}
|
key={headerGroup.id}
|
||||||
className={cn(
|
className={tableClassNames.headerRowClassName}
|
||||||
TABLE_DEFAULT_STYLING.headerRowClassName,
|
|
||||||
tableClassNames.headerRowClassName
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
{headerGroup.headers.map((header) => {
|
{headerGroup.headers.map((header) => {
|
||||||
const columnRelativeDepth =
|
const columnRelativeDepth =
|
||||||
@@ -318,7 +255,6 @@ const Table = <TData extends object>({
|
|||||||
{
|
{
|
||||||
'border-b': header.colSpan > 1,
|
'border-b': header.colSpan > 1,
|
||||||
},
|
},
|
||||||
TABLE_DEFAULT_STYLING.headerColumnClassName,
|
|
||||||
tableClassNames.headerColumnClassName
|
tableClassNames.headerColumnClassName
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -368,110 +304,34 @@ const Table = <TData extends object>({
|
|||||||
))}
|
))}
|
||||||
</thead>
|
</thead>
|
||||||
|
|
||||||
<tbody
|
<tbody className={tableClassNames.tableBodyClassName}>
|
||||||
className={cn(
|
{table.getRowModel().rows.map((row) => (
|
||||||
TABLE_DEFAULT_STYLING.tableBodyClassName,
|
<tr key={row.id} className={tableClassNames.bodyRowClassName}>
|
||||||
tableClassNames.tableBodyClassName
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{table.getRowModel().rows.map((row) => {
|
|
||||||
const customRowContent = renderCustomRow?.(row);
|
|
||||||
|
|
||||||
if (customRowContent) {
|
|
||||||
return renderCustomRow?.(row);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Fragment key={row.id}>
|
|
||||||
<tr
|
|
||||||
data-depth={row.depth}
|
|
||||||
className={cn(
|
|
||||||
row.depth > 0
|
|
||||||
? tableClassNames.bodySubRowClassName(row.depth)
|
|
||||||
: tableClassNames.bodyRowClassName,
|
|
||||||
{
|
|
||||||
[tableClassNames.selectedBodyRowClassName!]:
|
|
||||||
row.getIsSelected() && row.depth === 0,
|
|
||||||
[tableClassNames.selectedBodySubRowClassName(
|
|
||||||
row.depth
|
|
||||||
)!]: row.getIsSelected() && row.depth > 0,
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{row.getVisibleCells().map((cell) => (
|
{row.getVisibleCells().map((cell) => (
|
||||||
<td
|
<td
|
||||||
key={cell.id}
|
key={cell.id}
|
||||||
className={cn(
|
className={cn(
|
||||||
{ 'first:w-9 first:pr-0': withCheckbox },
|
{ 'first:w-9 first:pr-0': withCheckbox },
|
||||||
TABLE_DEFAULT_STYLING.bodyColumnClassName,
|
tableClassNames.bodyColumnClassName
|
||||||
row.depth > 0
|
|
||||||
? tableClassNames.bodySubRowColumnClassName(
|
|
||||||
row.depth
|
|
||||||
)
|
|
||||||
: tableClassNames.bodyColumnClassName
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{!isLoading &&
|
{!isLoading &&
|
||||||
flexRender(
|
flexRender(cell.column.columnDef.cell, cell.getContext())}
|
||||||
cell.column.columnDef.cell,
|
|
||||||
cell.getContext()
|
|
||||||
)}
|
|
||||||
|
|
||||||
{isLoading && (
|
{isLoading && <div className='skeleton w-full h-4' />}
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'skeleton w-full h-4',
|
|
||||||
tableClassNames.skeletonCellClassName
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</td>
|
</td>
|
||||||
))}
|
))}
|
||||||
</tr>
|
</tr>
|
||||||
|
))}
|
||||||
{row.getIsExpanded() && (
|
|
||||||
<>
|
|
||||||
{renderSubComponent && (
|
|
||||||
<tr
|
|
||||||
className={cn(
|
|
||||||
TABLE_DEFAULT_STYLING.bodySubRowClassName(1),
|
|
||||||
tableClassNames.bodySubRowClassName(1),
|
|
||||||
{
|
|
||||||
[tableClassNames.selectedBodySubRowClassName(1)]:
|
|
||||||
row.getIsSelected(),
|
|
||||||
}
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<td colSpan={row.getVisibleCells().length}>
|
|
||||||
{renderSubComponent({ row })}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
)}
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Fragment>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</tbody>
|
</tbody>
|
||||||
<tfoot
|
<tfoot className={cn(tableClassNames.tableFooterClassName)}>
|
||||||
className={cn(
|
|
||||||
TABLE_DEFAULT_STYLING.tableFooterClassName,
|
|
||||||
tableClassNames.tableFooterClassName
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{renderFooter && (
|
{renderFooter && (
|
||||||
<tr
|
<tr className={cn(tableClassNames.footerRowClassName)}>
|
||||||
className={cn(
|
|
||||||
TABLE_DEFAULT_STYLING.footerRowClassName,
|
|
||||||
tableClassNames.footerRowClassName
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{table.getAllLeafColumns().map((column) => (
|
{table.getAllLeafColumns().map((column) => (
|
||||||
<td
|
<td
|
||||||
key={column.id}
|
key={column.id}
|
||||||
className={cn(
|
className={cn(
|
||||||
{ 'first:w-9 first:pr-0': withCheckbox },
|
{ 'first:w-9 first:pr-0': withCheckbox },
|
||||||
TABLE_DEFAULT_STYLING.footerColumnClassName,
|
|
||||||
tableClassNames.footerColumnClassName
|
tableClassNames.footerColumnClassName
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -493,17 +353,8 @@ const Table = <TData extends object>({
|
|||||||
!isLoading &&
|
!isLoading &&
|
||||||
emptyContent}
|
emptyContent}
|
||||||
|
|
||||||
{data.length > 0 &&
|
{data.length > 0 && table.getRowModel().rows.length > 0 && !isLoading && (
|
||||||
table.getRowModel().rows.length > 0 &&
|
<div className={cn('mt-5', tableClassNames.paginationClassName)}>
|
||||||
!isLoading &&
|
|
||||||
withPagination && (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'mt-5',
|
|
||||||
TABLE_DEFAULT_STYLING.paginationClassName,
|
|
||||||
tableClassNames.paginationClassName
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Pagination
|
<Pagination
|
||||||
totalItems={isServerSideTable ? totalItems : table.getRowCount()}
|
totalItems={isServerSideTable ? totalItems : table.getRowCount()}
|
||||||
itemsPerPage={table.getState().pagination.pageSize}
|
itemsPerPage={table.getState().pagination.pageSize}
|
||||||
|
|||||||
+4
-22
@@ -21,14 +21,11 @@ export interface TabsProps
|
|||||||
className?:
|
className?:
|
||||||
| string
|
| string
|
||||||
| {
|
| {
|
||||||
container?: string;
|
|
||||||
wrapper?: string;
|
wrapper?: string;
|
||||||
tab?: string;
|
tab?: string;
|
||||||
content?: string;
|
content?: string;
|
||||||
tabHeaderWrapper?: string;
|
|
||||||
};
|
};
|
||||||
onTabChange?: (tabId: string) => void;
|
onTabChange?: (tabId: string) => void;
|
||||||
sideContent?: ReactNode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Tabs = ({
|
const Tabs = ({
|
||||||
@@ -40,7 +37,6 @@ const Tabs = ({
|
|||||||
activeTabId: controlledActiveId,
|
activeTabId: controlledActiveId,
|
||||||
className,
|
className,
|
||||||
onTabChange,
|
onTabChange,
|
||||||
sideContent,
|
|
||||||
...props
|
...props
|
||||||
}: TabsProps) => {
|
}: TabsProps) => {
|
||||||
// State internal hanya dipakai kalau `activeTabId` (controlled) tidak diset
|
// State internal hanya dipakai kalau `activeTabId` (controlled) tidak diset
|
||||||
@@ -57,13 +53,8 @@ const Tabs = ({
|
|||||||
onTabChange?.(tabId);
|
onTabChange?.(tabId);
|
||||||
};
|
};
|
||||||
|
|
||||||
const {
|
const { wrapper: wrapperClassName, tab: tabClassName } =
|
||||||
container: containerClassName,
|
typeof className === 'object'
|
||||||
wrapper: wrapperClassName,
|
|
||||||
tab: tabClassName,
|
|
||||||
content: contentClassName,
|
|
||||||
tabHeaderWrapper: tabHeaderWrapperClassName,
|
|
||||||
} = typeof className === 'object'
|
|
||||||
? className
|
? className
|
||||||
: { wrapper: className, tab: undefined };
|
: { wrapper: className, tab: undefined };
|
||||||
|
|
||||||
@@ -106,10 +97,6 @@ const Tabs = ({
|
|||||||
tabClassName
|
tabClassName
|
||||||
);
|
);
|
||||||
|
|
||||||
const getSideContentClasses = () => {
|
|
||||||
return cn('flex flex-row', tabHeaderWrapperClassName);
|
|
||||||
};
|
|
||||||
|
|
||||||
const activeContent = tabs.find((tab) => tab.id === activeTabId)?.content;
|
const activeContent = tabs.find((tab) => tab.id === activeTabId)?.content;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -117,10 +104,9 @@ const Tabs = ({
|
|||||||
{...props}
|
{...props}
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-full',
|
'w-full',
|
||||||
typeof className === 'string' ? className : containerClassName
|
typeof className === 'string' ? className : undefined
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className={getSideContentClasses()}>
|
|
||||||
<div role='tablist' className={getTabsClasses()}>
|
<div role='tablist' className={getTabsClasses()}>
|
||||||
{tabs.map(({ id, label, disabled }) => (
|
{tabs.map(({ id, label, disabled }) => (
|
||||||
<button
|
<button
|
||||||
@@ -134,12 +120,8 @@ const Tabs = ({
|
|||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
{sideContent && sideContent}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{activeContent && (
|
{activeContent && <div className='mt-4'>{activeContent}</div>}
|
||||||
<div className={cn('mt-4', contentClassName)}>{activeContent}</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,109 +1,111 @@
|
|||||||
import React, { ReactNode, useState, useRef } from 'react';
|
'use client';
|
||||||
|
|
||||||
|
import { ReactNode, useRef, useEffect, useState } from 'react';
|
||||||
import { cn } from '@/lib/helper';
|
import { cn } from '@/lib/helper';
|
||||||
|
|
||||||
export interface DropdownProps {
|
interface DropdownProps {
|
||||||
trigger: ReactNode;
|
trigger: ReactNode;
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
className?: {
|
position?:
|
||||||
wrapper?: string;
|
| 'top'
|
||||||
trigger?: string;
|
| 'bottom'
|
||||||
content?: string;
|
| 'left'
|
||||||
};
|
| 'right'
|
||||||
|
| 'top-start'
|
||||||
|
| 'top-end'
|
||||||
|
| 'bottom-start'
|
||||||
|
| 'bottom-end'
|
||||||
|
| 'left-start'
|
||||||
|
| 'left-end'
|
||||||
|
| 'right-start'
|
||||||
|
| 'right-end';
|
||||||
align?: 'start' | 'center' | 'end';
|
align?: 'start' | 'center' | 'end';
|
||||||
direction?: 'top' | 'bottom' | 'left' | 'right';
|
|
||||||
hover?: boolean;
|
hover?: boolean;
|
||||||
defaultOpen?: boolean;
|
className?: string;
|
||||||
open?: boolean;
|
contentClassName?: string;
|
||||||
close?: boolean;
|
|
||||||
controlled?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const Dropdown = ({
|
const Dropdown = ({
|
||||||
trigger,
|
trigger,
|
||||||
children,
|
children,
|
||||||
|
position = 'bottom',
|
||||||
|
align = 'start',
|
||||||
|
hover = false,
|
||||||
className,
|
className,
|
||||||
align,
|
contentClassName,
|
||||||
direction,
|
|
||||||
hover,
|
|
||||||
defaultOpen = false,
|
|
||||||
open,
|
|
||||||
close,
|
|
||||||
controlled = false,
|
|
||||||
}: DropdownProps) => {
|
}: DropdownProps) => {
|
||||||
const [isOpen, setIsOpen] = useState(defaultOpen);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const dropdownRef = useRef<HTMLDivElement>(null);
|
const dropdownRef = useRef<HTMLDivElement>(null);
|
||||||
|
|
||||||
const toggleDropdown = () => {
|
// Handle click outside to close dropdown
|
||||||
if (!controlled) {
|
useEffect(() => {
|
||||||
const newState = !isOpen;
|
const handleClickOutside = (event: MouseEvent) => {
|
||||||
setIsOpen(newState);
|
if (
|
||||||
|
dropdownRef.current &&
|
||||||
|
!dropdownRef.current.contains(event.target as Node)
|
||||||
|
) {
|
||||||
|
setIsOpen(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getWrapperClasses = () => {
|
if (isOpen) {
|
||||||
const openState = controlled ? open : isOpen;
|
document.addEventListener('mousedown', handleClickOutside);
|
||||||
|
|
||||||
return cn(
|
|
||||||
'dropdown',
|
|
||||||
{
|
|
||||||
'dropdown-start': align === 'start',
|
|
||||||
'dropdown-center': align === 'center',
|
|
||||||
'dropdown-end': align === 'end',
|
|
||||||
'dropdown-top': direction === 'top',
|
|
||||||
'dropdown-bottom': direction === 'bottom',
|
|
||||||
'dropdown-left': direction === 'left',
|
|
||||||
'dropdown-right': direction === 'right',
|
|
||||||
'dropdown-hover': hover,
|
|
||||||
'dropdown-open': openState && !close,
|
|
||||||
'dropdown-close': close,
|
|
||||||
},
|
|
||||||
className?.wrapper
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getTriggerClasses = () => {
|
|
||||||
return cn(className?.trigger);
|
|
||||||
};
|
|
||||||
|
|
||||||
const getContentClasses = () => {
|
|
||||||
return cn(
|
|
||||||
'dropdown-content z-[9999] shadow-sm bg-base-100 rounded-box',
|
|
||||||
className?.content
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (controlled) {
|
|
||||||
return (
|
|
||||||
<div className={getWrapperClasses()}>
|
|
||||||
{trigger}
|
|
||||||
{open && !close && (
|
|
||||||
<div tabIndex={-1} className={getContentClasses()}>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return () => {
|
||||||
<div ref={dropdownRef} className={getWrapperClasses()}>
|
document.removeEventListener('mousedown', handleClickOutside);
|
||||||
<div
|
};
|
||||||
tabIndex={0}
|
}, [isOpen]);
|
||||||
role='button'
|
|
||||||
className={getTriggerClasses()}
|
// Build position classes
|
||||||
onClick={toggleDropdown}
|
const getPositionClasses = () => {
|
||||||
onKeyDown={(e) => {
|
const classes: string[] = [];
|
||||||
if (e.key === 'Enter' || e.key === ' ') {
|
|
||||||
|
// Handle combined positions like 'top-start'
|
||||||
|
if (position.includes('-')) {
|
||||||
|
const [pos, al] = position.split('-');
|
||||||
|
classes.push(`dropdown-${pos}`);
|
||||||
|
classes.push(`dropdown-${al}`);
|
||||||
|
} else {
|
||||||
|
classes.push(`dropdown-${position}`);
|
||||||
|
if (align !== 'start') {
|
||||||
|
classes.push(`dropdown-${align}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return classes.join(' ');
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleToggle = (e: React.MouseEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
toggleDropdown();
|
e.stopPropagation();
|
||||||
}
|
// alert('clicked');
|
||||||
}}
|
setIsOpen(!isOpen);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div
|
||||||
|
ref={dropdownRef}
|
||||||
|
className={cn(
|
||||||
|
'dropdown',
|
||||||
|
getPositionClasses(),
|
||||||
|
hover && 'dropdown-hover',
|
||||||
|
isOpen && 'dropdown-open',
|
||||||
|
className
|
||||||
|
)}
|
||||||
>
|
>
|
||||||
|
{/* Trigger Button */}
|
||||||
|
<div onClick={handleToggle} className='cursor-pointer'>
|
||||||
{trigger}
|
{trigger}
|
||||||
</div>
|
</div>
|
||||||
{!close && (
|
|
||||||
<div tabIndex={-1} className={getContentClasses()}>
|
{/* Dropdown Content - Only render when open */}
|
||||||
|
{isOpen && (
|
||||||
|
<div
|
||||||
|
tabIndex={-1}
|
||||||
|
className={cn('dropdown-content z-[10]', contentClassName)}
|
||||||
|
onClick={() => setIsOpen(false)} // Close on item click
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,203 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useEffect, useMemo, useState } from 'react';
|
|
||||||
|
|
||||||
import { Icon } from '@iconify/react';
|
|
||||||
import { BaseApproval } from '@/types/api/api-general';
|
|
||||||
import Button from '@/components/Button';
|
|
||||||
|
|
||||||
import { cn, formatDate } from '@/lib/helper';
|
|
||||||
|
|
||||||
interface ApprovalStepsV2Props {
|
|
||||||
approvals?: BaseApproval[];
|
|
||||||
steps: {
|
|
||||||
step_number: number;
|
|
||||||
step_name: string;
|
|
||||||
}[];
|
|
||||||
maxVisibleSteps?: number;
|
|
||||||
className?: {
|
|
||||||
wrapper?: string;
|
|
||||||
stepsWrapper?: string;
|
|
||||||
stepsContainer?: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const ApprovalStepsV2 = ({
|
|
||||||
approvals,
|
|
||||||
steps,
|
|
||||||
maxVisibleSteps = 2,
|
|
||||||
className,
|
|
||||||
}: ApprovalStepsV2Props) => {
|
|
||||||
const [isSeeAll, setIsSeeAll] = useState(false);
|
|
||||||
const [formattedApprovals, setFormattedApprovals] = useState<
|
|
||||||
(BaseApproval & { isActive: boolean })[]
|
|
||||||
>([]);
|
|
||||||
|
|
||||||
const latestApprovalStepNumber =
|
|
||||||
approvals?.[approvals.length - 1].step_number ?? 0;
|
|
||||||
|
|
||||||
const lastStepNumber = steps[steps.length - 1].step_number;
|
|
||||||
|
|
||||||
const isLatestApprovalStepNumberLessThanLastStepNumber =
|
|
||||||
latestApprovalStepNumber < lastStepNumber;
|
|
||||||
|
|
||||||
const slicedFormattedApprovals = useMemo(() => {
|
|
||||||
return formattedApprovals.slice(0, isSeeAll ? undefined : maxVisibleSteps);
|
|
||||||
}, [formattedApprovals, isSeeAll]);
|
|
||||||
|
|
||||||
const seeMoreClickHandler = () => {
|
|
||||||
setIsSeeAll((prevVal) => !prevVal);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (approvals) {
|
|
||||||
const tempFormattedApprovals: (BaseApproval & { isActive: boolean })[] =
|
|
||||||
[];
|
|
||||||
|
|
||||||
approvals.forEach((approval) => {
|
|
||||||
tempFormattedApprovals.push({
|
|
||||||
...approval,
|
|
||||||
isActive: true,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
if (isLatestApprovalStepNumberLessThanLastStepNumber) {
|
|
||||||
const latestApprovalStepNumberIndexInSteps = steps.findIndex(
|
|
||||||
(step) => step.step_number === latestApprovalStepNumber
|
|
||||||
);
|
|
||||||
|
|
||||||
const slicedSteps = steps.slice(
|
|
||||||
latestApprovalStepNumberIndexInSteps + 1
|
|
||||||
);
|
|
||||||
|
|
||||||
slicedSteps.forEach((step) => {
|
|
||||||
tempFormattedApprovals.push({
|
|
||||||
action: 'APPROVED',
|
|
||||||
action_at: new Date().toISOString(),
|
|
||||||
action_by: {
|
|
||||||
id: 0,
|
|
||||||
id_user: 0,
|
|
||||||
email: '',
|
|
||||||
name: '',
|
|
||||||
},
|
|
||||||
step_name: step.step_name,
|
|
||||||
step_number: step.step_number,
|
|
||||||
isActive: false,
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setFormattedApprovals(tempFormattedApprovals);
|
|
||||||
}
|
|
||||||
}, [approvals]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'w-full p-4 flex flex-col border-b border-base-content/10',
|
|
||||||
className?.wrapper
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<h4 className='text-base font-medium text-base-content/50 font-roboto'>
|
|
||||||
Progress Details
|
|
||||||
</h4>
|
|
||||||
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'mt-6 mb-8 flex flex-col gap-10',
|
|
||||||
className?.stepsWrapper
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{slicedFormattedApprovals.map((approval, idx) => {
|
|
||||||
const isApprovalActionCreated = approval.action === 'CREATED';
|
|
||||||
const isApprovalActionUpdated = approval.action === 'UPDATED';
|
|
||||||
const isApprovalActionRejected = approval.action === 'REJECTED';
|
|
||||||
const isApprovalActionApproved = approval.action === 'APPROVED';
|
|
||||||
|
|
||||||
const approvalIcon =
|
|
||||||
isApprovalActionCreated || isApprovalActionUpdated
|
|
||||||
? 'heroicons:clock-solid'
|
|
||||||
: isApprovalActionRejected
|
|
||||||
? 'heroicons:x-circle-solid'
|
|
||||||
: isApprovalActionApproved
|
|
||||||
? 'heroicons:check-badge-solid'
|
|
||||||
: 'heroicons:check-badge-solid';
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div key={idx} className='w-full flex flex-row items-stretch gap-3'>
|
|
||||||
<div className='w-fit self-stretch relative'>
|
|
||||||
<div className='w-fit h-fit flex flex-col items-start'>
|
|
||||||
<Icon
|
|
||||||
icon={approvalIcon}
|
|
||||||
width={24}
|
|
||||||
height={24}
|
|
||||||
className={cn({
|
|
||||||
'text-warning':
|
|
||||||
isApprovalActionCreated || isApprovalActionUpdated,
|
|
||||||
'text-error': isApprovalActionRejected,
|
|
||||||
'text-success': isApprovalActionApproved,
|
|
||||||
'text-base-content/20': !approval.isActive,
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{idx < formattedApprovals.length - 1 && (
|
|
||||||
<div className='absolute top-6 left-1/2 -translate-x-1/2 w-0 min-h-full h-[calc(100%)] mx-auto my-2 border border-dashed border-base-content/10' />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
className={cn('w-full flex flex-col gap-1 text-base-content', {
|
|
||||||
'text-base-content/20': !approval.isActive,
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<div className='flex flex-col'>
|
|
||||||
<span className='text-xs'>{approval.step_name}</span>
|
|
||||||
<span className='text-sm font-semibold'>
|
|
||||||
{(isApprovalActionCreated || isApprovalActionUpdated) &&
|
|
||||||
'Diajukan oleh '}
|
|
||||||
{isApprovalActionRejected && 'Ditolak oleh '}
|
|
||||||
{isApprovalActionApproved && 'Disetujui oleh '}
|
|
||||||
{approval.isActive ? approval.action_by.name : '...'}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{approval.isActive && (
|
|
||||||
<p className='w-full max-w-60 p-3 bg-base-content/5 rounded-xl text-xs text-base-content/50'>
|
|
||||||
Created at :{' '}
|
|
||||||
{formatDate(approval.action_at, 'DD-MM-YYYY, HH:mm')}
|
|
||||||
<br />
|
|
||||||
Notes : {approval.notes ?? '-'}
|
|
||||||
</p>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{formattedApprovals.length > maxVisibleSteps && (
|
|
||||||
<Button
|
|
||||||
variant='outline'
|
|
||||||
color='none'
|
|
||||||
onClick={seeMoreClickHandler}
|
|
||||||
className={cn(
|
|
||||||
'px-3 py-2 gap-2.5 text-sm text-base-content/50 border border-base-content/10 rounded-lg transition-all'
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Icon
|
|
||||||
icon='heroicons-outline:chevron-double-down'
|
|
||||||
width={20}
|
|
||||||
height={20}
|
|
||||||
className={cn('transition-all duration-300', {
|
|
||||||
'-rotate-180': isSeeAll,
|
|
||||||
})}
|
|
||||||
/>
|
|
||||||
See {isSeeAll ? 'Less' : 'More'}
|
|
||||||
</Button>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ApprovalStepsV2;
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
import Button, { ButtonProps } from '@/components/Button';
|
|
||||||
import { getFilledFormikValuesCount } from '@/lib/formik-helper';
|
|
||||||
import { cn } from '@/lib/helper';
|
|
||||||
import { Icon } from '@iconify/react';
|
|
||||||
import { FormikValues } from 'formik';
|
|
||||||
|
|
||||||
export type ButtonFilterProps = ButtonProps & {
|
|
||||||
values: FormikValues;
|
|
||||||
onClick: () => void;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 'bg-gradient-to-t from-blue-50 to-blue-100 border-blue-500 text-blue-600 hover:from-blue-100 hover:to-blue-200
|
|
||||||
|
|
||||||
const ButtonFilter = ({ values, onClick, ...props }: ButtonFilterProps) => {
|
|
||||||
return (
|
|
||||||
<Button
|
|
||||||
{...props}
|
|
||||||
onClick={onClick}
|
|
||||||
variant='outline'
|
|
||||||
color='none'
|
|
||||||
className={cn(
|
|
||||||
'rounded-lg max-h-10 font-semibold text-sm gap-1.5',
|
|
||||||
'text-sm text-base-content/50 border border-base-content/10 shadow-button-soft',
|
|
||||||
getFilledFormikValuesCount(values) > 0
|
|
||||||
? 'border-primary-gradient text-primary rounded-lg!'
|
|
||||||
: 'rounded-lg',
|
|
||||||
props.className
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<Icon
|
|
||||||
icon='heroicons:funnel'
|
|
||||||
width={20}
|
|
||||||
height={20}
|
|
||||||
className={
|
|
||||||
getFilledFormikValuesCount(values) > 0 ? 'text-blue-600' : ''
|
|
||||||
}
|
|
||||||
/>
|
|
||||||
Filter
|
|
||||||
{getFilledFormikValuesCount(values) > 0 && (
|
|
||||||
<span className='w-5 h-5 text-white bg-[#FF3535] rounded-lg border border-base-300 flex items-center justify-center text-xs'>
|
|
||||||
{getFilledFormikValuesCount(values)}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</Button>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default ButtonFilter;
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import Button from '@/components/Button';
|
|
||||||
|
|
||||||
const PageNotFound = () => {
|
|
||||||
return (
|
|
||||||
<div className='w-full h-full flex-1 flex flex-col justify-center items-center gap-4'>
|
|
||||||
<h2 className='text-2xl font-bold text-error'>Halaman Tidak Ditemukan</h2>
|
|
||||||
<p className='text-gray-600 text-center'>
|
|
||||||
Halaman atau data yang anda cari tidak ditemukan.
|
|
||||||
</p>
|
|
||||||
<Button href='/dashboard' className='text-base-100'>
|
|
||||||
Kembali ke Dashboard
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default PageNotFound;
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
import Button from '@/components/Button';
|
|
||||||
|
|
||||||
const PermissionNotFound = () => {
|
|
||||||
return (
|
|
||||||
<div className='w-full h-screen flex flex-col justify-center items-center gap-4'>
|
|
||||||
<h2 className='text-2xl font-bold text-error'>
|
|
||||||
Hak Akses Tidak Ditemukan
|
|
||||||
</h2>
|
|
||||||
<p className='text-gray-600 text-center'>
|
|
||||||
Anda tidak memiliki hak akses untuk mengakses halaman ini.
|
|
||||||
</p>
|
|
||||||
<Button href='/dashboard' className='text-base-100'>
|
|
||||||
Kembali ke Dashboard
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default PermissionNotFound;
|
|
||||||
@@ -5,7 +5,6 @@ import useSWR from 'swr';
|
|||||||
|
|
||||||
import { useAuth } from '@/services/hooks/useAuth';
|
import { useAuth } from '@/services/hooks/useAuth';
|
||||||
import { httpClientFetcher, SWRHttpKey } from '@/services/http/client';
|
import { httpClientFetcher, SWRHttpKey } from '@/services/http/client';
|
||||||
import { AuthApi } from '@/services/api/auth';
|
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
||||||
import { BaseApiResponse, GetMeResponse } from '@/types/api/api-general';
|
import { BaseApiResponse, GetMeResponse } from '@/types/api/api-general';
|
||||||
import { AxiosError } from 'axios';
|
import { AxiosError } from 'axios';
|
||||||
@@ -28,9 +27,6 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
|
|||||||
SWRHttpKey
|
SWRHttpKey
|
||||||
>('/sso/userinfo', httpClientFetcher, {
|
>('/sso/userinfo', httpClientFetcher, {
|
||||||
shouldRetryOnError: false,
|
shouldRetryOnError: false,
|
||||||
|
|
||||||
// refresh every 12 minutes
|
|
||||||
refreshInterval: 12 * 60 * 1000,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -56,27 +52,6 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
|
|||||||
setIsLoadingUser(isLoadingUserResponse);
|
setIsLoadingUser(isLoadingUserResponse);
|
||||||
}, [isLoadingUserResponse]);
|
}, [isLoadingUserResponse]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const interval = setInterval(
|
|
||||||
async () => {
|
|
||||||
await AuthApi.refresh();
|
|
||||||
},
|
|
||||||
12 * 60 * 1000
|
|
||||||
);
|
|
||||||
|
|
||||||
return () => clearInterval(interval);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const refreshUserSession = async () => {
|
|
||||||
await AuthApi.refresh();
|
|
||||||
};
|
|
||||||
|
|
||||||
if (user) {
|
|
||||||
refreshUserSession();
|
|
||||||
}
|
|
||||||
}, [user]);
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
(isLoadingUserResponse && !userResponse && !userErrorResponse) ||
|
(isLoadingUserResponse && !userResponse && !userErrorResponse) ||
|
||||||
(!userResponse && !userErrorResponse)
|
(!userResponse && !userErrorResponse)
|
||||||
@@ -88,7 +63,7 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isLoadingUserResponse && userErrorResponse) {
|
if (userErrorResponse) {
|
||||||
return (
|
return (
|
||||||
<div className='w-full h-screen flex flex-col justify-center items-center gap-4'>
|
<div className='w-full h-screen flex flex-col justify-center items-center gap-4'>
|
||||||
<h2 className='text-2xl font-bold text-error'>Authentication Failed</h2>
|
<h2 className='text-2xl font-bold text-error'>Authentication Failed</h2>
|
||||||
@@ -96,7 +71,10 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
|
|||||||
Please try refreshing the page or contact support if the problem
|
Please try refreshing the page or contact support if the problem
|
||||||
persists.
|
persists.
|
||||||
</p>
|
</p>
|
||||||
<button className='btn btn-primary' onClick={() => redirectToSSO()}>
|
<button
|
||||||
|
className='btn btn-primary'
|
||||||
|
onClick={() => window.location.reload()}
|
||||||
|
>
|
||||||
Retry
|
Retry
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { useAuth } from '@/services/hooks/useAuth';
|
|
||||||
|
|
||||||
interface RequirePermissionProps {
|
|
||||||
children: React.ReactNode;
|
|
||||||
permissions: string | string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
const RequirePermission = ({
|
|
||||||
children,
|
|
||||||
permissions,
|
|
||||||
}: RequirePermissionProps) => {
|
|
||||||
const { permissionCheck } = useAuth();
|
|
||||||
|
|
||||||
const isPermitted =
|
|
||||||
typeof permissions === 'string'
|
|
||||||
? permissionCheck(permissions)
|
|
||||||
: permissions.some((permission) => permissionCheck(permission));
|
|
||||||
|
|
||||||
if (!isPermitted) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return <>{children}</>;
|
|
||||||
};
|
|
||||||
|
|
||||||
export default RequirePermission;
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
import Badge from '@/components/Badge';
|
|
||||||
import { cn } from '@/lib/helper';
|
|
||||||
import { Color } from '@/types/theme';
|
|
||||||
|
|
||||||
interface StatusBadgeProps {
|
|
||||||
color: Color;
|
|
||||||
text: string;
|
|
||||||
className?: {
|
|
||||||
badge?: string;
|
|
||||||
status?: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const StatusBadge = ({
|
|
||||||
color = 'neutral',
|
|
||||||
text,
|
|
||||||
className,
|
|
||||||
}: StatusBadgeProps) => {
|
|
||||||
return (
|
|
||||||
<Badge
|
|
||||||
variant='soft'
|
|
||||||
className={{
|
|
||||||
badge: cn(
|
|
||||||
'px-2 py-1 w-full flex flex-row justify-start gap-1 rounded-lg border border-base-content/10 text-xs font-medium text-base-content',
|
|
||||||
{
|
|
||||||
'bg-base-content/5': color === 'neutral',
|
|
||||||
'bg-success/30': color === 'success',
|
|
||||||
'bg-error/20': color === 'error',
|
|
||||||
'bg-primary/20': color === 'info',
|
|
||||||
'bg-[#FF9A20]/12': color === 'warning',
|
|
||||||
'bg-[#1166EF]/12': color === 'primary',
|
|
||||||
},
|
|
||||||
className?.badge
|
|
||||||
),
|
|
||||||
status: cn(className?.status),
|
|
||||||
}}
|
|
||||||
color={color}
|
|
||||||
>
|
|
||||||
<svg
|
|
||||||
height='12'
|
|
||||||
width='12'
|
|
||||||
xmlns='http://www.w3.org/2000/svg'
|
|
||||||
className={cn({
|
|
||||||
'text-base-content/10': color === 'neutral',
|
|
||||||
'text-[#008000]': color === 'success',
|
|
||||||
'text-error': color === 'error',
|
|
||||||
'text-primary': color === 'info',
|
|
||||||
'text-[#FF9A20]': color === 'warning',
|
|
||||||
'text-[#1166EF]': color === 'primary',
|
|
||||||
})}
|
|
||||||
>
|
|
||||||
<circle r='6' cx='6' cy='6' fill='currentColor' />
|
|
||||||
</svg>
|
|
||||||
|
|
||||||
{text}
|
|
||||||
</Badge>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default StatusBadge;
|
|
||||||
@@ -58,7 +58,6 @@ const DrawerHeader = ({
|
|||||||
if (leftIconOnClick) {
|
if (leftIconOnClick) {
|
||||||
return (
|
return (
|
||||||
<button
|
<button
|
||||||
type='button'
|
|
||||||
onClick={leftIconOnClick}
|
onClick={leftIconOnClick}
|
||||||
className='hover:text-gray-400 bg-transparent border-none p-0'
|
className='hover:text-gray-400 bg-transparent border-none p-0'
|
||||||
>
|
>
|
||||||
@@ -73,12 +72,12 @@ const DrawerHeader = ({
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
'flex flex-row justify-between items-center px-4 pt-4 pb-4 border-b border-base-content/10',
|
'flex flex-row justify-between items-center px-4 pt-4',
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{/* Left Side */}
|
{/* Left Side */}
|
||||||
<div className='flex flex-row h-full gap-3 items-center'>
|
<div className='flex flex-row h-full gap-2 items-center'>
|
||||||
{renderLeftIcon()}
|
{renderLeftIcon()}
|
||||||
|
|
||||||
{showDivider && subtitle && (
|
{showDivider && subtitle && (
|
||||||
@@ -86,12 +85,7 @@ const DrawerHeader = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{subtitle && (
|
{subtitle && (
|
||||||
<div
|
<div className={cn('text-sm text-neutral', subtitleClassName)}>
|
||||||
className={cn(
|
|
||||||
'text-sm font-medium text-base-content/50',
|
|
||||||
subtitleClassName
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{subtitle}
|
{subtitle}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -1,84 +0,0 @@
|
|||||||
import Alert from '@/components/Alert';
|
|
||||||
import Button from '@/components/Button';
|
|
||||||
import { cn } from '@/lib/helper';
|
|
||||||
import { Icon } from '@iconify/react';
|
|
||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Alert Unique Error List
|
|
||||||
* @param formErrorList - Array of error messages
|
|
||||||
* @param onClose - Function to close the alert
|
|
||||||
*/
|
|
||||||
const AlertErrorList = ({
|
|
||||||
formErrorList,
|
|
||||||
className,
|
|
||||||
onClose,
|
|
||||||
title,
|
|
||||||
}: {
|
|
||||||
formErrorList: string[];
|
|
||||||
className?: {
|
|
||||||
alert?: string;
|
|
||||||
button?: string;
|
|
||||||
headerWrapper?: string;
|
|
||||||
headerIcon?: string;
|
|
||||||
headerText?: string;
|
|
||||||
titleWrapper?: string;
|
|
||||||
ul?: string;
|
|
||||||
li?: string;
|
|
||||||
};
|
|
||||||
onClose: () => void;
|
|
||||||
title?: string;
|
|
||||||
}) => {
|
|
||||||
if (formErrorList.length === 0) return null;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Alert
|
|
||||||
color='error'
|
|
||||||
className={cn(
|
|
||||||
'w-full flex flex-col gap-2 px-3 rounded-lg',
|
|
||||||
className?.alert
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'flex justify-between items-center gap-2 w-full',
|
|
||||||
className?.headerWrapper
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div className={cn('flex items-center gap-2', className?.titleWrapper)}>
|
|
||||||
<Icon
|
|
||||||
icon='material-symbols:error-outline'
|
|
||||||
className={cn(className?.headerIcon)}
|
|
||||||
width={20}
|
|
||||||
height={20}
|
|
||||||
/>
|
|
||||||
<span className={cn('font-semibold text-sm', className?.headerText)}>
|
|
||||||
{title || `Terdapat ${formErrorList.length} error pada form:`}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
<Button
|
|
||||||
onClick={onClose}
|
|
||||||
variant='link'
|
|
||||||
className={cn('ml-auto p-0 w-fit text-white', className?.button)}
|
|
||||||
color='none'
|
|
||||||
>
|
|
||||||
<Icon icon='material-symbols:close' width={20} height={20} />
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
<ul
|
|
||||||
className={cn(
|
|
||||||
'list-disc list-inside pl-4 space-y-1.5 w-full',
|
|
||||||
className?.ul
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{formErrorList.map((error, index) => (
|
|
||||||
<li key={index} className={cn('text-sm', className?.li)}>
|
|
||||||
{error}
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</Alert>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default AlertErrorList;
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { View, StyleSheet } from '@react-pdf/renderer';
|
|
||||||
import { PdfThead, PdfColumn } from './PdfThead';
|
|
||||||
import { PdfTbody, PdfTbodyCell } from './PdfTbody';
|
|
||||||
import { PdfTfoot, PdfTfootCell } from './PdfTfoot';
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
table: {
|
|
||||||
borderWidth: 1,
|
|
||||||
borderColor: '#000000',
|
|
||||||
marginBottom: 15,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
interface PdfTableProps {
|
|
||||||
columns: PdfColumn[];
|
|
||||||
data: PdfTbodyCell[][];
|
|
||||||
footer?: PdfTfootCell[];
|
|
||||||
footerLabel?: string;
|
|
||||||
firstRow?: {
|
|
||||||
valueKey: string;
|
|
||||||
value: number;
|
|
||||||
align?: 'right';
|
|
||||||
color?: string;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PdfTable = ({
|
|
||||||
columns,
|
|
||||||
data,
|
|
||||||
footer,
|
|
||||||
footerLabel = 'Total',
|
|
||||||
firstRow,
|
|
||||||
}: PdfTableProps) => {
|
|
||||||
return (
|
|
||||||
<View style={styles.table}>
|
|
||||||
<PdfThead columns={columns} />
|
|
||||||
<PdfTbody columns={columns} rows={data} firstRow={firstRow} />
|
|
||||||
{footer && footer.length > 0 && (
|
|
||||||
<PdfTfoot columns={columns} cells={footer} label={footerLabel} />
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,219 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { Text, View, StyleSheet } from '@react-pdf/renderer';
|
|
||||||
|
|
||||||
export interface PdfColumn {
|
|
||||||
key: string;
|
|
||||||
header: string;
|
|
||||||
flex: number;
|
|
||||||
align?: 'left' | 'center' | 'right';
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PdfTbodyCell {
|
|
||||||
key: string;
|
|
||||||
value: string | number | React.ReactNode;
|
|
||||||
align?: 'left' | 'center' | 'right';
|
|
||||||
color?: string;
|
|
||||||
formatAs?: 'text' | 'date' | 'currency' | 'number';
|
|
||||||
formatDate?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
tableRow: {
|
|
||||||
flexDirection: 'row',
|
|
||||||
},
|
|
||||||
tableBorderBottom: {
|
|
||||||
borderBottomWidth: 1,
|
|
||||||
borderBottomColor: '#000000',
|
|
||||||
borderBottomStyle: 'solid',
|
|
||||||
},
|
|
||||||
tableCell: {
|
|
||||||
flex: 1,
|
|
||||||
borderRightWidth: 1,
|
|
||||||
borderRightColor: '#000000',
|
|
||||||
borderRightStyle: 'solid',
|
|
||||||
padding: 4,
|
|
||||||
fontSize: 7,
|
|
||||||
textAlign: 'left',
|
|
||||||
},
|
|
||||||
tableCellLast: {
|
|
||||||
flex: 1,
|
|
||||||
padding: 4,
|
|
||||||
fontSize: 7,
|
|
||||||
borderRightWidth: 0,
|
|
||||||
},
|
|
||||||
tableCellRight: {
|
|
||||||
flex: 1,
|
|
||||||
borderRightWidth: 1,
|
|
||||||
borderRightColor: '#000000',
|
|
||||||
borderRightStyle: 'solid',
|
|
||||||
padding: 4,
|
|
||||||
fontSize: 7,
|
|
||||||
textAlign: 'right',
|
|
||||||
},
|
|
||||||
tableCellCenter: {
|
|
||||||
flex: 1,
|
|
||||||
borderRightWidth: 1,
|
|
||||||
borderRightColor: '#000000',
|
|
||||||
borderRightStyle: 'solid',
|
|
||||||
padding: 4,
|
|
||||||
fontSize: 7,
|
|
||||||
textAlign: 'center',
|
|
||||||
},
|
|
||||||
tableCellNo: {
|
|
||||||
flex: 0.5,
|
|
||||||
borderRightWidth: 1,
|
|
||||||
borderRightColor: '#000000',
|
|
||||||
borderRightStyle: 'solid',
|
|
||||||
padding: 4,
|
|
||||||
fontSize: 7,
|
|
||||||
textAlign: 'center',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
interface PdfTbodyProps {
|
|
||||||
columns: PdfColumn[];
|
|
||||||
rows: PdfTbodyCell[][];
|
|
||||||
firstRow?: {
|
|
||||||
valueKey: string;
|
|
||||||
value: number;
|
|
||||||
align?: 'right';
|
|
||||||
color?: string;
|
|
||||||
};
|
|
||||||
formatDate?: (date: string, format: string) => string;
|
|
||||||
formatNumber?: (num: number) => string;
|
|
||||||
formatCurrency?: (num: number) => string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PdfTbody = ({ columns, rows, firstRow }: PdfTbodyProps) => {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{/* First Row */}
|
|
||||||
{firstRow && (
|
|
||||||
<View style={[styles.tableRow, styles.tableBorderBottom]}>
|
|
||||||
{columns.map((column, index) => {
|
|
||||||
const isLastColumn = index === columns.length - 1;
|
|
||||||
const isfirstRowColumn = column.key === firstRow.valueKey;
|
|
||||||
const align = column.align || 'center';
|
|
||||||
|
|
||||||
const cellStyle =
|
|
||||||
column.key === 'no'
|
|
||||||
? [styles.tableCellNo, { flex: column.flex }]
|
|
||||||
: isfirstRowColumn
|
|
||||||
? [
|
|
||||||
styles.tableCellRight,
|
|
||||||
{
|
|
||||||
flex: column.flex,
|
|
||||||
color: firstRow.color || 'black',
|
|
||||||
borderRightWidth: isLastColumn ? 0 : 1,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: align === 'right'
|
|
||||||
? [
|
|
||||||
styles.tableCellRight,
|
|
||||||
{
|
|
||||||
flex: column.flex,
|
|
||||||
borderRightWidth: isLastColumn ? 0 : 1,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: align === 'center'
|
|
||||||
? [
|
|
||||||
styles.tableCellCenter,
|
|
||||||
{
|
|
||||||
flex: column.flex,
|
|
||||||
borderRightWidth: isLastColumn ? 0 : 1,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: isLastColumn
|
|
||||||
? [
|
|
||||||
styles.tableCellLast,
|
|
||||||
{
|
|
||||||
flex: column.flex,
|
|
||||||
borderRightWidth: 0,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: [styles.tableCell, { flex: column.flex }];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View key={column.key} style={cellStyle}>
|
|
||||||
<Text>{isfirstRowColumn ? firstRow.value : ''}</Text>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</View>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{/* Data Rows */}
|
|
||||||
{rows.map((row, rowIndex) => {
|
|
||||||
const isLastRow = rowIndex === rows.length - 1;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View
|
|
||||||
key={rowIndex}
|
|
||||||
style={[
|
|
||||||
styles.tableRow,
|
|
||||||
!isLastRow ? styles.tableBorderBottom : {},
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{columns.map((column, colIndex) => {
|
|
||||||
const cell = row.find((c) => c.key === column.key);
|
|
||||||
const isLastColumn = colIndex === columns.length - 1;
|
|
||||||
const align = cell?.align || column.align || 'center';
|
|
||||||
|
|
||||||
const cellStyle =
|
|
||||||
column.key === 'no'
|
|
||||||
? [styles.tableCellNo, { flex: column.flex }]
|
|
||||||
: align === 'right'
|
|
||||||
? [
|
|
||||||
styles.tableCellRight,
|
|
||||||
{
|
|
||||||
flex: column.flex,
|
|
||||||
color: cell?.color || 'black',
|
|
||||||
borderRightWidth: isLastColumn ? 0 : 1,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: align === 'center'
|
|
||||||
? [
|
|
||||||
styles.tableCellCenter,
|
|
||||||
{
|
|
||||||
flex: column.flex,
|
|
||||||
color: cell?.color || 'black',
|
|
||||||
borderRightWidth: isLastColumn ? 0 : 1,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: isLastColumn
|
|
||||||
? [
|
|
||||||
styles.tableCellLast,
|
|
||||||
{ flex: column.flex, borderRightWidth: 0 },
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
styles.tableCell,
|
|
||||||
{
|
|
||||||
flex: column.flex,
|
|
||||||
color: cell?.color || 'black',
|
|
||||||
borderRightWidth: isLastColumn ? 0 : 1,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View key={column.key} style={cellStyle}>
|
|
||||||
{cell?.value !== undefined &&
|
|
||||||
cell?.value !== null &&
|
|
||||||
cell?.value !== '' ? (
|
|
||||||
typeof cell.value === 'object' ? (
|
|
||||||
cell.value
|
|
||||||
) : (
|
|
||||||
<Text>{String(cell.value)}</Text>
|
|
||||||
)
|
|
||||||
) : (
|
|
||||||
<Text>-</Text>
|
|
||||||
)}
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { Text, View, StyleSheet } from '@react-pdf/renderer';
|
|
||||||
|
|
||||||
export interface PdfColumn {
|
|
||||||
key: string;
|
|
||||||
header: string;
|
|
||||||
flex: number;
|
|
||||||
align?: 'left' | 'center' | 'right';
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface PdfTfootCell {
|
|
||||||
key: string;
|
|
||||||
value: string | number;
|
|
||||||
align?: 'left' | 'center' | 'right';
|
|
||||||
flex?: number;
|
|
||||||
color?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
tableRow: {
|
|
||||||
flexDirection: 'row',
|
|
||||||
},
|
|
||||||
summaryRow: {
|
|
||||||
backgroundColor: '#F0F0F0',
|
|
||||||
fontWeight: 'bold',
|
|
||||||
},
|
|
||||||
tableCell: {
|
|
||||||
flex: 1,
|
|
||||||
borderRightWidth: 1,
|
|
||||||
borderRightColor: '#000000',
|
|
||||||
borderRightStyle: 'solid',
|
|
||||||
padding: 4,
|
|
||||||
fontSize: 7,
|
|
||||||
textAlign: 'left',
|
|
||||||
},
|
|
||||||
tableCellLast: {
|
|
||||||
flex: 1,
|
|
||||||
padding: 4,
|
|
||||||
fontSize: 7,
|
|
||||||
borderRightWidth: 0,
|
|
||||||
},
|
|
||||||
tableCellRight: {
|
|
||||||
flex: 1,
|
|
||||||
borderRightWidth: 1,
|
|
||||||
borderRightColor: '#000000',
|
|
||||||
borderRightStyle: 'solid',
|
|
||||||
padding: 4,
|
|
||||||
fontSize: 7,
|
|
||||||
textAlign: 'right',
|
|
||||||
},
|
|
||||||
tableCellCenter: {
|
|
||||||
flex: 1,
|
|
||||||
borderRightWidth: 1,
|
|
||||||
borderRightColor: '#000000',
|
|
||||||
borderRightStyle: 'solid',
|
|
||||||
padding: 4,
|
|
||||||
fontSize: 7,
|
|
||||||
textAlign: 'center',
|
|
||||||
},
|
|
||||||
tableCellNo: {
|
|
||||||
flex: 0.5,
|
|
||||||
borderRightWidth: 1,
|
|
||||||
borderRightColor: '#000000',
|
|
||||||
borderRightStyle: 'solid',
|
|
||||||
padding: 4,
|
|
||||||
fontSize: 7,
|
|
||||||
textAlign: 'center',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
interface PdfTfootProps {
|
|
||||||
columns: PdfColumn[];
|
|
||||||
cells: PdfTfootCell[];
|
|
||||||
label?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PdfTfoot = ({
|
|
||||||
columns,
|
|
||||||
cells,
|
|
||||||
label = 'Total',
|
|
||||||
}: PdfTfootProps) => {
|
|
||||||
return (
|
|
||||||
<View style={[styles.tableRow, styles.summaryRow]}>
|
|
||||||
{columns.map((column, index) => {
|
|
||||||
const isLastColumn = index === columns.length - 1;
|
|
||||||
const cellData = cells.find((c) => c.key === column.key);
|
|
||||||
|
|
||||||
const cellStyle =
|
|
||||||
column.key === 'no'
|
|
||||||
? [
|
|
||||||
styles.tableCellNo,
|
|
||||||
{ flex: column.flex, borderRightWidth: isLastColumn ? 0 : 1 },
|
|
||||||
]
|
|
||||||
: cellData?.align === 'right'
|
|
||||||
? [
|
|
||||||
styles.tableCellRight,
|
|
||||||
{
|
|
||||||
flex: column.flex,
|
|
||||||
color: cellData?.color || 'black',
|
|
||||||
borderRightWidth: isLastColumn ? 0 : 1,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: cellData?.align === 'center'
|
|
||||||
? [
|
|
||||||
styles.tableCellCenter,
|
|
||||||
{
|
|
||||||
flex: column.flex,
|
|
||||||
color: cellData?.color || 'black',
|
|
||||||
borderRightWidth: isLastColumn ? 0 : 1,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: isLastColumn
|
|
||||||
? [styles.tableCellLast, { flex: column.flex }]
|
|
||||||
: [
|
|
||||||
styles.tableCell,
|
|
||||||
{
|
|
||||||
flex: column.flex,
|
|
||||||
color: cellData?.color || 'black',
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View key={column.key} style={cellStyle}>
|
|
||||||
<Text>{column.key === 'no' ? label : cellData?.value || ''}</Text>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,89 +0,0 @@
|
|||||||
'use client';
|
|
||||||
|
|
||||||
import { Text, View, StyleSheet } from '@react-pdf/renderer';
|
|
||||||
|
|
||||||
export interface PdfColumn {
|
|
||||||
key: string;
|
|
||||||
header: string;
|
|
||||||
flex: number;
|
|
||||||
align?: 'left' | 'center' | 'right';
|
|
||||||
}
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
tableRow: {
|
|
||||||
flexDirection: 'row',
|
|
||||||
},
|
|
||||||
tableHeader: {
|
|
||||||
backgroundColor: '#F5F5F5',
|
|
||||||
},
|
|
||||||
tableCellHeader: {
|
|
||||||
flex: 1,
|
|
||||||
borderRightWidth: 1,
|
|
||||||
borderRightColor: '#000000',
|
|
||||||
borderRightStyle: 'solid',
|
|
||||||
padding: 4,
|
|
||||||
fontSize: 7,
|
|
||||||
fontWeight: 'bold',
|
|
||||||
backgroundColor: '#F5F5F5',
|
|
||||||
borderBottomWidth: 1,
|
|
||||||
borderBottomColor: '#000000',
|
|
||||||
borderBottomStyle: 'solid',
|
|
||||||
paddingVertical: 12,
|
|
||||||
textAlign: 'center',
|
|
||||||
},
|
|
||||||
tableCellHeaderRight: {
|
|
||||||
flex: 1,
|
|
||||||
borderRightWidth: 1,
|
|
||||||
borderRightColor: '#000000',
|
|
||||||
borderRightStyle: 'solid',
|
|
||||||
padding: 4,
|
|
||||||
fontSize: 7,
|
|
||||||
fontWeight: 'bold',
|
|
||||||
backgroundColor: '#F5F5F5',
|
|
||||||
textAlign: 'right',
|
|
||||||
borderBottomWidth: 1,
|
|
||||||
borderBottomColor: '#000000',
|
|
||||||
borderBottomStyle: 'solid',
|
|
||||||
paddingVertical: 12,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
interface PdfTheadProps {
|
|
||||||
columns: PdfColumn[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export const PdfThead = ({ columns }: PdfTheadProps) => {
|
|
||||||
return (
|
|
||||||
<View style={[styles.tableRow, styles.tableHeader]}>
|
|
||||||
{columns.map((column, index) => {
|
|
||||||
const align = column.align || 'center';
|
|
||||||
const isLastColumn = index === columns.length - 1;
|
|
||||||
|
|
||||||
const cellStyle =
|
|
||||||
align === 'right'
|
|
||||||
? [
|
|
||||||
styles.tableCellHeaderRight,
|
|
||||||
{
|
|
||||||
flex: column.flex,
|
|
||||||
textAlign: 'right' as const,
|
|
||||||
borderRightWidth: isLastColumn ? 0 : 1,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: [
|
|
||||||
styles.tableCellHeader,
|
|
||||||
{
|
|
||||||
flex: column.flex,
|
|
||||||
textAlign: align as 'left' | 'center' | 'right',
|
|
||||||
borderRightWidth: isLastColumn ? 0 : 1,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
return (
|
|
||||||
<View key={column.key} style={cellStyle}>
|
|
||||||
<Text>{column.header}</Text>
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</View>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
export { PdfTable } from './PdfTable';
|
|
||||||
export { PdfThead } from './PdfThead';
|
|
||||||
export { PdfTbody } from './PdfTbody';
|
|
||||||
export { PdfTfoot } from './PdfTfoot';
|
|
||||||
export type { PdfColumn } from './PdfThead';
|
|
||||||
export type { PdfTbodyCell } from './PdfTbody';
|
|
||||||
export type { PdfTfootCell } from './PdfTfoot';
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
import IconSkeleton from '@/components/helper/skeleton/IconSkeleton';
|
|
||||||
import { Icon } from '@iconify/react';
|
|
||||||
|
|
||||||
const DataStateSkeleton = ({
|
|
||||||
icon,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
}: {
|
|
||||||
icon: React.ReactNode;
|
|
||||||
title: string;
|
|
||||||
description: string;
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<div className='flex flex-col items-center justify-center'>
|
|
||||||
<IconSkeleton
|
|
||||||
className={{
|
|
||||||
outer: 'mb-2.25',
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{icon}
|
|
||||||
</IconSkeleton>
|
|
||||||
<h3 className='text-base-content/50 font-semibold text-sm mb-1'>
|
|
||||||
{title}
|
|
||||||
</h3>
|
|
||||||
<p className='text-base-content/50 text-xs text-center max-w-xs'>
|
|
||||||
{description}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default DataStateSkeleton;
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
import { cn } from '@/lib/helper';
|
|
||||||
import { ReactNode } from 'react';
|
|
||||||
|
|
||||||
const IconSkeleton = ({
|
|
||||||
children,
|
|
||||||
className,
|
|
||||||
}: {
|
|
||||||
children: ReactNode;
|
|
||||||
className?: {
|
|
||||||
outer?: string;
|
|
||||||
inner?: string;
|
|
||||||
};
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'w-12.5 h-12.5 bg-[var(--main-color-base-100,#FFFFFF)] border border-base-content/10 rounded-[0.875rem] shadow-[0px_25px_50px_-12px_#00000040] flex items-center justify-center',
|
|
||||||
className?.outer
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'w-9.5 h-9.5 bg-primary rounded-lg border border-primary flex items-center justify-center shadow-[inset_0px_4px_4px_0px_#FFFFFF80,inset_0px_2px_0px_0px_#FFFFFF80]',
|
|
||||||
className?.inner
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default IconSkeleton;
|
|
||||||
@@ -113,15 +113,7 @@ const DateInput = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectSingle = (selectedDate?: Date) => {
|
const handleSelectSingle = (selectedDate?: Date) => {
|
||||||
if (!selectedDate) {
|
if (!selectedDate) return;
|
||||||
setSelected(undefined);
|
|
||||||
setDisplayValue('');
|
|
||||||
const syntheticEvent = {
|
|
||||||
target: { name, value: '' },
|
|
||||||
} as unknown as React.ChangeEvent<HTMLInputElement>;
|
|
||||||
onChange?.(syntheticEvent);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (minDate && selectedDate < minDate) {
|
if (minDate && selectedDate < minDate) {
|
||||||
setInternalError(`Tanggal tidak boleh sebelum ${min}`);
|
setInternalError(`Tanggal tidak boleh sebelum ${min}`);
|
||||||
return;
|
return;
|
||||||
@@ -144,15 +136,7 @@ const DateInput = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSelectRange = (range?: { from?: Date; to?: Date }) => {
|
const handleSelectRange = (range?: { from?: Date; to?: Date }) => {
|
||||||
if (!range) {
|
if (!range) return;
|
||||||
setSelectedRange({});
|
|
||||||
setDisplayValue('');
|
|
||||||
const syntheticEvent = {
|
|
||||||
target: { name, value: { from: '', to: '' } },
|
|
||||||
} as unknown as React.ChangeEvent<HTMLInputElement>;
|
|
||||||
onChange?.(syntheticEvent);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setSelectedRange(range);
|
setSelectedRange(range);
|
||||||
|
|
||||||
const fromStr = range.from ? formatDate(range.from, 'DD/MM/YYYY') : '';
|
const fromStr = range.from ? formatDate(range.from, 'DD/MM/YYYY') : '';
|
||||||
@@ -204,12 +188,17 @@ const DateInput = ({
|
|||||||
const finalErrorMessage = internalError || externalErrorMessage;
|
const finalErrorMessage = internalError || externalErrorMessage;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('w-full flex flex-col text-start', className?.wrapper)}>
|
<div
|
||||||
|
className={cn(
|
||||||
|
'w-full flex flex-col gap-2 text-start',
|
||||||
|
className?.wrapper
|
||||||
|
)}
|
||||||
|
>
|
||||||
{label && (
|
{label && (
|
||||||
<label
|
<label
|
||||||
htmlFor={name}
|
htmlFor={name}
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-full py-2 text-xs font-semibold leading-5',
|
'w-full text-sm font-normal leading-5',
|
||||||
{ 'text-error': finalIsError },
|
{ 'text-error': finalIsError },
|
||||||
className?.label
|
className?.label
|
||||||
)}
|
)}
|
||||||
@@ -226,7 +215,7 @@ const DateInput = ({
|
|||||||
|
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
'input h-fit bg-inherit px-3 py-2.5 text-base font-normal leading-6 w-full rounded-lg transition-all duration-200 flex items-center border border-base-content/10',
|
'input h-12 bg-inherit px-4 py-2 text-base font-normal leading-6 w-full rounded transition-all duration-200 flex items-center border',
|
||||||
{
|
{
|
||||||
'border-error': finalIsError,
|
'border-error': finalIsError,
|
||||||
'border-success': externalValid && !finalIsError,
|
'border-success': externalValid && !finalIsError,
|
||||||
@@ -245,10 +234,7 @@ const DateInput = ({
|
|||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
readOnly // ✅ tidak bisa diketik manual
|
readOnly // ✅ tidak bisa diketik manual
|
||||||
className={cn(
|
className={cn(
|
||||||
'grow bg-transparent cursor-pointer focus:outline-none text-sm leading-tight',
|
'grow bg-transparent cursor-pointer focus:outline-none',
|
||||||
{
|
|
||||||
'cursor-not-allowed': readOnly,
|
|
||||||
},
|
|
||||||
className?.input
|
className?.input
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
@@ -259,10 +245,10 @@ const DateInput = ({
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<Icon
|
<Icon
|
||||||
icon='heroicons:calendar-date-range'
|
icon='uil:calendar'
|
||||||
width={15}
|
width={24}
|
||||||
height={15}
|
height={24}
|
||||||
className='cursor-pointer text-base-content/20'
|
className='cursor-pointer text-dark'
|
||||||
onClick={(e) =>
|
onClick={(e) =>
|
||||||
handleClick(e as unknown as React.MouseEvent<HTMLInputElement>)
|
handleClick(e as unknown as React.MouseEvent<HTMLInputElement>)
|
||||||
}
|
}
|
||||||
@@ -270,17 +256,17 @@ const DateInput = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{!finalIsError && bottomLabel && (
|
{!finalIsError && bottomLabel && (
|
||||||
<p className='w-full mt-1.5 text-xs opacity-60'>{bottomLabel}</p>
|
<p className='w-full text-sm opacity-60'>{bottomLabel}</p>
|
||||||
)}
|
)}
|
||||||
{finalIsError && finalErrorMessage && (
|
{finalIsError && finalErrorMessage && (
|
||||||
<p className='w-full mt-1.5 text-xs text-error'>{finalErrorMessage}</p>
|
<p className='w-full text-sm text-error'>{finalErrorMessage}</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Modal
|
<Modal
|
||||||
ref={calendarModal.ref}
|
ref={calendarModal.ref}
|
||||||
className={{
|
className={{
|
||||||
modal: 'rounded',
|
modal: 'rounded',
|
||||||
modalBox: `max-w-max flex flex-col`,
|
modalBox: `!max-w-max min-h-${isRange ? '124' : '110'} flex flex-col`,
|
||||||
}}
|
}}
|
||||||
closeOnBackdrop
|
closeOnBackdrop
|
||||||
>
|
>
|
||||||
@@ -296,11 +282,7 @@ const DateInput = ({
|
|||||||
endMonth={maxDate ?? new Date(new Date().getFullYear() + 5, 11)}
|
endMonth={maxDate ?? new Date(new Date().getFullYear() + 5, 11)}
|
||||||
selected={selectedRange as DateRange}
|
selected={selectedRange as DateRange}
|
||||||
onSelect={handleSelectRange}
|
onSelect={handleSelectRange}
|
||||||
footer={
|
footer={<div className='text-center mt-3'>{displayValue}</div>}
|
||||||
<div className='text-center py-2 text-base-content/65 font-semibold text-xs'>
|
|
||||||
{displayValue}
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
disabled={
|
disabled={
|
||||||
[
|
[
|
||||||
minDate ? { before: minDate } : undefined,
|
minDate ? { before: minDate } : undefined,
|
||||||
@@ -330,26 +312,17 @@ const DateInput = ({
|
|||||||
)}
|
)}
|
||||||
<div className='mt-auto flex flex-col gap-2'>
|
<div className='mt-auto flex flex-col gap-2'>
|
||||||
{isRange && (
|
{isRange && (
|
||||||
<small className='text-base-content/65'>
|
<small className='text-secondary'>
|
||||||
Tekan dua kali untuk reset tanggal awal
|
Tekan dua kali untuk memilih tanggal awal
|
||||||
</small>
|
</small>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<div className='flex h-full justify-end items-end gap-1.5 mt-3'>
|
<div className='flex h-full justify-end items-end gap-2'>
|
||||||
<Button
|
<Button type='button' color='warning' onClick={handleResetDate}>
|
||||||
type='button'
|
|
||||||
color='none'
|
|
||||||
className='bg-transparent hover:bg-base-content/10 border-none text-base text-base-content/65 px-3'
|
|
||||||
onClick={handleResetDate}
|
|
||||||
>
|
|
||||||
Reset
|
Reset
|
||||||
</Button>
|
</Button>
|
||||||
{isRange && (
|
{isRange && (
|
||||||
<Button
|
<Button type='button' onClick={handleSaveDate}>
|
||||||
type='button'
|
|
||||||
className='rounded-lg px-3 py-2 text-white'
|
|
||||||
onClick={handleSaveDate}
|
|
||||||
>
|
|
||||||
Simpan
|
Simpan
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import TextArea, { TextAreaProps } from '@/components/input/TextArea';
|
|||||||
|
|
||||||
interface DebouncedTextAreaProps extends TextAreaProps {
|
interface DebouncedTextAreaProps extends TextAreaProps {
|
||||||
delay?: number;
|
delay?: number;
|
||||||
ref?: React.RefObject<HTMLTextAreaElement | null>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const DebouncedTextArea = (props: DebouncedTextAreaProps) => {
|
const DebouncedTextArea = (props: DebouncedTextAreaProps) => {
|
||||||
@@ -20,11 +19,6 @@ const DebouncedTextArea = (props: DebouncedTextAreaProps) => {
|
|||||||
const [debouncedChangeEvent] = useDebounce(internalChangeEvent, delay ?? 300);
|
const [debouncedChangeEvent] = useDebounce(internalChangeEvent, delay ?? 300);
|
||||||
const [debouncedValue] = useDebounce(internalValue, delay ?? 300);
|
const [debouncedValue] = useDebounce(internalValue, delay ?? 300);
|
||||||
|
|
||||||
// Sync internal value with external props.value when it changes (e.g., form reset)
|
|
||||||
useEffect(() => {
|
|
||||||
setInternalValue(props.value);
|
|
||||||
}, [props.value]);
|
|
||||||
|
|
||||||
const internalChangeHandler: ChangeEventHandler<HTMLTextAreaElement> = (
|
const internalChangeHandler: ChangeEventHandler<HTMLTextAreaElement> = (
|
||||||
e
|
e
|
||||||
) => {
|
) => {
|
||||||
@@ -41,7 +35,6 @@ const DebouncedTextArea = (props: DebouncedTextAreaProps) => {
|
|||||||
return (
|
return (
|
||||||
<TextArea
|
<TextArea
|
||||||
{...props}
|
{...props}
|
||||||
ref={props.ref}
|
|
||||||
value={internalValue}
|
value={internalValue}
|
||||||
onChange={internalChangeHandler}
|
onChange={internalChangeHandler}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -24,11 +24,6 @@ const DebouncedTextInput = (props: DebouncedTextInputProps) => {
|
|||||||
setInternalChangeEvent(e);
|
setInternalChangeEvent(e);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sync internal value with external value prop changes (e.g., from reset)
|
|
||||||
useEffect(() => {
|
|
||||||
setInternalValue(props.value);
|
|
||||||
}, [props.value]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (debouncedChangeEvent) {
|
if (debouncedChangeEvent) {
|
||||||
onChange?.(debouncedChangeEvent);
|
onChange?.(debouncedChangeEvent);
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ const FileInput = ({
|
|||||||
isError,
|
isError,
|
||||||
errorMessage,
|
errorMessage,
|
||||||
disabled = false,
|
disabled = false,
|
||||||
required = false,
|
|
||||||
onChange,
|
onChange,
|
||||||
onBlur,
|
onBlur,
|
||||||
readOnly = false,
|
readOnly = false,
|
||||||
@@ -41,7 +40,7 @@ const FileInput = ({
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-full flex flex-col gap-0 text-start rounded-lg',
|
'w-full flex flex-col gap-2 text-start',
|
||||||
className?.wrapper
|
className?.wrapper
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -49,7 +48,7 @@ const FileInput = ({
|
|||||||
<label
|
<label
|
||||||
htmlFor={name}
|
htmlFor={name}
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-full py-2 text-xs font-semibold leading-5',
|
'w-full text-sm font-normal leading-5',
|
||||||
{
|
{
|
||||||
'text-error': isError,
|
'text-error': isError,
|
||||||
},
|
},
|
||||||
@@ -57,13 +56,6 @@ const FileInput = ({
|
|||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{label}
|
{label}
|
||||||
{required && (
|
|
||||||
<>
|
|
||||||
<span className='tooltip tooltip-error' data-tip='required'>
|
|
||||||
<span className='text-error'> *</span>
|
|
||||||
</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</label>
|
</label>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -77,19 +69,15 @@ const FileInput = ({
|
|||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
onBlur={onBlur}
|
onBlur={onBlur}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
className={cn(
|
className={cn('grow file-input w-full h-12 rounded', className?.input)}
|
||||||
'grow file-input w-full h-fit px-3 py-1.5 text-sm font-normal leading-6 rounded-lg! outline-none! transition-all duration-200 bg-white border-base-content/10',
|
|
||||||
className?.input
|
|
||||||
)}
|
|
||||||
readOnly={readOnly}
|
readOnly={readOnly}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{!isError && bottomLabel && (
|
{bottomLabel && (
|
||||||
<p className='w-full mt-1.5 text-xs opacity-60'>{bottomLabel}</p>
|
<p className='w-full text-sm opacity-60'>{bottomLabel}</p>
|
||||||
)}
|
|
||||||
{isError && errorMessage && (
|
|
||||||
<p className='w-full mt-1.5 text-xs text-error'>{errorMessage}</p>
|
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{isError && <p className='w-full text-sm text-error'>{errorMessage}</p>}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -9,20 +9,15 @@ import Select, {
|
|||||||
SingleValue,
|
SingleValue,
|
||||||
components as ReactSelectComponents,
|
components as ReactSelectComponents,
|
||||||
ControlProps,
|
ControlProps,
|
||||||
MenuListProps,
|
|
||||||
} from 'react-select';
|
} from 'react-select';
|
||||||
import CreatableSelect from 'react-select/creatable';
|
import CreatableSelect from 'react-select/creatable';
|
||||||
import makeAnimated from 'react-select/animated';
|
import makeAnimated from 'react-select/animated';
|
||||||
import { useDebounce } from 'use-debounce';
|
import { useDebounce } from 'use-debounce';
|
||||||
import { cn, getByPath } from '@/lib/helper';
|
import { cn, getByPath } from '@/lib/helper';
|
||||||
import useSWRInfinite from 'swr/infinite';
|
import useSWR from 'swr';
|
||||||
import { httpClientFetcher } from '@/services/http/client';
|
import { httpClientFetcher } from '@/services/http/client';
|
||||||
import {
|
import { BaseApiResponse } from '@/types/api/api-general';
|
||||||
BaseApiResponse,
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
ErrorApiResponse,
|
|
||||||
SuccessApiResponse,
|
|
||||||
} from '@/types/api/api-general';
|
|
||||||
import { isResponseError, isResponseSuccess } from '@/lib/api-helper';
|
|
||||||
|
|
||||||
export interface OptionType {
|
export interface OptionType {
|
||||||
value: string | number;
|
value: string | number;
|
||||||
@@ -40,9 +35,7 @@ interface SelectInputBaseProps<T = OptionType> {
|
|||||||
bottomLabel?: ReactNode;
|
bottomLabel?: ReactNode;
|
||||||
options: T[];
|
options: T[];
|
||||||
optionComponent?: OptionComponent<T>;
|
optionComponent?: OptionComponent<T>;
|
||||||
components?: Partial<typeof ReactSelectComponents>;
|
|
||||||
isDisabled?: boolean;
|
isDisabled?: boolean;
|
||||||
readOnly?: boolean;
|
|
||||||
isLoading?: boolean;
|
isLoading?: boolean;
|
||||||
isClearable?: boolean;
|
isClearable?: boolean;
|
||||||
isRtl?: boolean;
|
isRtl?: boolean;
|
||||||
@@ -54,9 +47,6 @@ interface SelectInputBaseProps<T = OptionType> {
|
|||||||
wrapper?: string;
|
wrapper?: string;
|
||||||
label?: string;
|
label?: string;
|
||||||
select?: string;
|
select?: string;
|
||||||
inputPrefix?: string;
|
|
||||||
inputSuffix?: string;
|
|
||||||
inputPrefixSuffixWrapper?: string;
|
|
||||||
};
|
};
|
||||||
isError?: boolean;
|
isError?: boolean;
|
||||||
errorMessage?: string;
|
errorMessage?: string;
|
||||||
@@ -65,16 +55,10 @@ interface SelectInputBaseProps<T = OptionType> {
|
|||||||
delay?: number;
|
delay?: number;
|
||||||
onInputChange?: (search: string) => void;
|
onInputChange?: (search: string) => void;
|
||||||
startAdornment?: ReactNode;
|
startAdornment?: ReactNode;
|
||||||
inputPrefix?: ReactNode;
|
|
||||||
inputSuffix?: ReactNode;
|
|
||||||
menuPortalTarget?: HTMLElement | null;
|
menuPortalTarget?: HTMLElement | null;
|
||||||
closeMenuOnSelect?: boolean;
|
|
||||||
hideSelectedOptions?: boolean;
|
|
||||||
onMenuScrollToBottom?: ((event: WheelEvent | TouchEvent) => void) | undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SelectInputProps<T = OptionType>
|
interface SelectInputProps<T = OptionType> extends SelectInputBaseProps<T> {
|
||||||
extends SelectInputBaseProps<T> {
|
|
||||||
createables?: boolean;
|
createables?: boolean;
|
||||||
value?: T | T[] | null;
|
value?: T | T[] | null;
|
||||||
onChange?: (val: T | T[] | null) => void;
|
onChange?: (val: T | T[] | null) => void;
|
||||||
@@ -89,7 +73,7 @@ const CustomControl = <
|
|||||||
>(
|
>(
|
||||||
props: ControlProps<Option, IsMulti, Group>
|
props: ControlProps<Option, IsMulti, Group>
|
||||||
) => {
|
) => {
|
||||||
const { children, innerProps } = props;
|
const { children } = props;
|
||||||
|
|
||||||
const customProps = props.selectProps as unknown as {
|
const customProps = props.selectProps as unknown as {
|
||||||
shouldShowAdornment?: boolean;
|
shouldShowAdornment?: boolean;
|
||||||
@@ -101,7 +85,7 @@ const CustomControl = <
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<ReactSelectComponents.Control {...props}>
|
<ReactSelectComponents.Control {...props}>
|
||||||
<div className='flex-1 pl-3 gap-1 flex items-center' {...innerProps}>
|
<div className='flex-1 px-4! py-1.5 gap-1 flex items-center'>
|
||||||
{shouldShowAdornment && startAdornment}
|
{shouldShowAdornment && startAdornment}
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
@@ -109,29 +93,6 @@ const CustomControl = <
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const CustomMenuList = <
|
|
||||||
Option,
|
|
||||||
IsMulti extends boolean,
|
|
||||||
Group extends GroupBase<Option>,
|
|
||||||
>(
|
|
||||||
props: MenuListProps<Option, IsMulti, Group>
|
|
||||||
) => {
|
|
||||||
const { children, selectProps, options } = props;
|
|
||||||
const { isLoading } = selectProps;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<ReactSelectComponents.MenuList {...props}>
|
|
||||||
{children}
|
|
||||||
|
|
||||||
{options.length > 0 && isLoading && (
|
|
||||||
<div className='px-3 py-2 rounded-md text-center text-gray-400'>
|
|
||||||
<span className='loading loading-spinner loading-md' />
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</ReactSelectComponents.MenuList>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
||||||
const {
|
const {
|
||||||
label,
|
label,
|
||||||
@@ -140,7 +101,6 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
|||||||
onChange,
|
onChange,
|
||||||
options,
|
options,
|
||||||
optionComponent,
|
optionComponent,
|
||||||
components: customComponents,
|
|
||||||
isDisabled,
|
isDisabled,
|
||||||
isLoading,
|
isLoading,
|
||||||
isClearable,
|
isClearable,
|
||||||
@@ -158,13 +118,7 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
|||||||
createables = false,
|
createables = false,
|
||||||
onInputChange,
|
onInputChange,
|
||||||
startAdornment,
|
startAdornment,
|
||||||
inputPrefix,
|
|
||||||
inputSuffix,
|
|
||||||
menuPortalTarget,
|
menuPortalTarget,
|
||||||
closeMenuOnSelect,
|
|
||||||
hideSelectedOptions,
|
|
||||||
onMenuScrollToBottom,
|
|
||||||
readOnly,
|
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const [internalInputValue, setInternalInputValue] = useState('');
|
const [internalInputValue, setInternalInputValue] = useState('');
|
||||||
@@ -174,18 +128,14 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
|||||||
|
|
||||||
const components = useMemo(() => {
|
const components = useMemo(() => {
|
||||||
const base = isAnimated ? animatedComponents : {};
|
const base = isAnimated ? animatedComponents : {};
|
||||||
const mergedComponents = { ...base, IndicatorSeparator: () => null };
|
const customComponents = { ...base, IndicatorSeparator: () => null };
|
||||||
|
|
||||||
if (startAdornment) {
|
if (startAdornment) {
|
||||||
mergedComponents.Control = CustomControl;
|
customComponents.Control = CustomControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (customComponents) {
|
return customComponents;
|
||||||
Object.assign(mergedComponents, customComponents);
|
}, [isAnimated, startAdornment]);
|
||||||
}
|
|
||||||
|
|
||||||
return mergedComponents;
|
|
||||||
}, [isAnimated, startAdornment, customComponents]);
|
|
||||||
|
|
||||||
const internalInputChangeHandler = (val: string, meta: InputActionMeta) => {
|
const internalInputChangeHandler = (val: string, meta: InputActionMeta) => {
|
||||||
if (meta.action === 'input-change') setInternalInputValue(val);
|
if (meta.action === 'input-change') setInternalInputValue(val);
|
||||||
@@ -213,11 +163,16 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('w-full flex flex-col text-start', className?.wrapper)}>
|
<div
|
||||||
|
className={cn(
|
||||||
|
'w-full flex flex-col gap-2 text-start',
|
||||||
|
className?.wrapper
|
||||||
|
)}
|
||||||
|
>
|
||||||
{label && (
|
{label && (
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
'w-full py-2 text-xs font-semibold leading-5',
|
'w-full text-sm font-normal leading-5',
|
||||||
{ 'text-error': isError },
|
{ 'text-error': isError },
|
||||||
className?.label
|
className?.label
|
||||||
)}
|
)}
|
||||||
@@ -234,29 +189,6 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{inputPrefix || inputSuffix ? (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'relative flex text-sm',
|
|
||||||
className?.inputPrefixSuffixWrapper
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{inputPrefix && (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'inline-flex items-center px-3 border border-r-0 border-base-content/10 rounded-l-lg transition-all duration-200',
|
|
||||||
{
|
|
||||||
'bg-gray-100 border-base-content/10': !isDisabled,
|
|
||||||
'bg-gray-50 border-base-content/10': isDisabled,
|
|
||||||
'border-error': isError,
|
|
||||||
},
|
|
||||||
className?.inputPrefix
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{inputPrefix}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<SelectComponent<T, boolean, GroupBase<T>>
|
<SelectComponent<T, boolean, GroupBase<T>>
|
||||||
instanceId='select'
|
instanceId='select'
|
||||||
value={value ?? (isMulti ? [] : null)}
|
value={value ?? (isMulti ? [] : null)}
|
||||||
@@ -267,185 +199,44 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
|||||||
onInputChange={internalInputChangeHandler}
|
onInputChange={internalInputChangeHandler}
|
||||||
onMenuClose={() => setInternalInputValue('')}
|
onMenuClose={() => setInternalInputValue('')}
|
||||||
isMulti={isMulti}
|
isMulti={isMulti}
|
||||||
isDisabled={isDisabled || readOnly}
|
isDisabled={isDisabled}
|
||||||
isLoading={isLoading}
|
isLoading={isLoading}
|
||||||
isClearable={isClearable}
|
isClearable={isClearable}
|
||||||
isRtl={isRtl}
|
isRtl={isRtl}
|
||||||
isSearchable={isSearchable}
|
isSearchable={isSearchable}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
closeMenuOnSelect={closeMenuOnSelect}
|
|
||||||
hideSelectedOptions={hideSelectedOptions}
|
|
||||||
className={cn('w-full flex-1', className?.select)}
|
|
||||||
classNames={{
|
|
||||||
control: ({ isFocused, isDisabled }) =>
|
|
||||||
cn('w-full border bg-white transition-shadow', 'rounded-lg!', {
|
|
||||||
'cursor-pointer!': !readOnly && !isDisabled,
|
|
||||||
'border-red-500! ring-2 ring-red-200': isError,
|
|
||||||
'border-indigo-500 ring-2 ring-indigo-200':
|
|
||||||
isFocused && !startAdornment,
|
|
||||||
'border-base-content/10!': !isError && !isFocused,
|
|
||||||
'bg-gray-100 text-gray-400 cursor-not-allowed':
|
|
||||||
isDisabled && !readOnly,
|
|
||||||
'bg-transparent! cursor-not-allowed!': readOnly,
|
|
||||||
'rounded-l-none!': inputPrefix && !startAdornment,
|
|
||||||
'rounded-r-none!': inputSuffix && !startAdornment,
|
|
||||||
}),
|
|
||||||
valueContainer: () => cn('flex-1 px-3! pr-2! py-2.5! gap-1'),
|
|
||||||
placeholder: () =>
|
|
||||||
cn({
|
|
||||||
'text-gray-400 text-sm leading-tight': !isError,
|
|
||||||
'text-red-300!': isError,
|
|
||||||
}),
|
|
||||||
singleValue: () =>
|
|
||||||
cn({
|
|
||||||
'm-0! text-gray-900 text-sm leading-tight': !isError,
|
|
||||||
'text-error!': isError,
|
|
||||||
'text-gray-900!': readOnly,
|
|
||||||
}),
|
|
||||||
input: () => cn('text-gray-900 m-0! p-0! text-sm leading-tight'),
|
|
||||||
indicatorsContainer: () =>
|
|
||||||
cn('flex items-center gap-1 pr-3 py-2'),
|
|
||||||
dropdownIndicator: ({ isFocused }) =>
|
|
||||||
cn('p-0! rounded hover:bg-gray-100', {
|
|
||||||
'text-gray-900': isFocused,
|
|
||||||
'text-gray-500': !isFocused,
|
|
||||||
'text-error!': isError,
|
|
||||||
}),
|
|
||||||
clearIndicator: () => cn('p-0! rounded hover:bg-gray-100'),
|
|
||||||
menu: () =>
|
|
||||||
cn(
|
|
||||||
'border border-base-content/5 rounded-xl! bg-base-100 shadow-lg! my-1.5!'
|
|
||||||
),
|
|
||||||
menuList: () => cn('p-0! max-h-60 overflow-auto'),
|
|
||||||
option: ({ isFocused, isSelected }) =>
|
|
||||||
cn('px-3 py-2 rounded-md cursor-pointer!', {
|
|
||||||
'bg-indigo-600 text-white': isFocused,
|
|
||||||
'bg-blue-500!': isSelected,
|
|
||||||
'text-gray-700': !isFocused && !isSelected,
|
|
||||||
}),
|
|
||||||
multiValue: ({ getValue, index }) => {
|
|
||||||
const selectedValues = getValue() as T[];
|
|
||||||
return cn(
|
|
||||||
'bg-base-200! rounded-lg! py-[3px] px-2.5 m-0! flex items-center gap-1! w-fit gap-2!',
|
|
||||||
selectedValues[index]?.className
|
|
||||||
);
|
|
||||||
},
|
|
||||||
multiValueRemove: () => cn('p-0! w-3 h-3'),
|
|
||||||
multiValueLabel: ({ getValue, index }) => {
|
|
||||||
const selectedValues = getValue() as T[];
|
|
||||||
return cn(
|
|
||||||
'p-0! text-base-content! text-xs!',
|
|
||||||
selectedValues[index]?.labelClassName
|
|
||||||
);
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
components={{
|
|
||||||
...components,
|
|
||||||
...(optionComponent ? { Option: optionComponent } : {}),
|
|
||||||
MenuList: CustomMenuList,
|
|
||||||
}}
|
|
||||||
{...(startAdornment && {
|
|
||||||
shouldShowAdornment,
|
|
||||||
startAdornment,
|
|
||||||
})}
|
|
||||||
menuPortalTarget={
|
|
||||||
typeof document !== 'undefined'
|
|
||||||
? (menuPortalTarget ?? document.body)
|
|
||||||
: undefined
|
|
||||||
}
|
|
||||||
styles={{
|
|
||||||
menuPortal: (base) => ({ ...base, zIndex: 9999 }),
|
|
||||||
multiValue(base) {
|
|
||||||
return {
|
|
||||||
...base,
|
|
||||||
borderRadius: '8px',
|
|
||||||
};
|
|
||||||
},
|
|
||||||
}}
|
|
||||||
onMenuScrollToBottom={onMenuScrollToBottom}
|
|
||||||
/>
|
|
||||||
|
|
||||||
{inputSuffix && (
|
|
||||||
<div
|
|
||||||
className={cn(
|
|
||||||
'inline-flex items-center px-3 border border-l-0 border-base-content/10 rounded-r-lg transition-all duration-200',
|
|
||||||
{
|
|
||||||
'bg-gray-100 border-base-content/10': !isDisabled,
|
|
||||||
'bg-gray-50 border-base-content/10': isDisabled,
|
|
||||||
'border-error': isError,
|
|
||||||
},
|
|
||||||
className?.inputSuffix
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
{inputSuffix}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<SelectComponent<T, boolean, GroupBase<T>>
|
|
||||||
instanceId='select'
|
|
||||||
value={value ?? (isMulti ? [] : null)}
|
|
||||||
onChange={onChange ? handleChange : undefined}
|
|
||||||
options={options}
|
|
||||||
menuIsOpen={openMenu}
|
|
||||||
inputValue={internalInputValue}
|
|
||||||
onInputChange={internalInputChangeHandler}
|
|
||||||
onMenuClose={() => setInternalInputValue('')}
|
|
||||||
isMulti={isMulti}
|
|
||||||
isDisabled={isDisabled || readOnly}
|
|
||||||
isLoading={isLoading}
|
|
||||||
isClearable={isClearable}
|
|
||||||
isRtl={isRtl}
|
|
||||||
isSearchable={isSearchable}
|
|
||||||
placeholder={placeholder}
|
|
||||||
closeMenuOnSelect={closeMenuOnSelect}
|
|
||||||
hideSelectedOptions={hideSelectedOptions}
|
|
||||||
className={cn('w-full', className?.select)}
|
className={cn('w-full', className?.select)}
|
||||||
classNames={{
|
classNames={{
|
||||||
|
...(!startAdornment && {
|
||||||
control: ({ isFocused, isDisabled }) =>
|
control: ({ isFocused, isDisabled }) =>
|
||||||
cn(
|
cn(
|
||||||
'w-full border bg-white transition-shadow',
|
'w-full min-h-12! rounded border bg-white transition-shadow cursor-pointer!',
|
||||||
// Gunakan rounded-lg untuk semua kasus
|
|
||||||
'rounded-lg!',
|
|
||||||
{
|
{
|
||||||
'cursor-pointer!': !readOnly && !isDisabled,
|
|
||||||
'border-red-500! ring-2 ring-red-200': isError,
|
'border-red-500! ring-2 ring-red-200': isError,
|
||||||
'border-indigo-500 ring-2 ring-indigo-200':
|
'border-indigo-500 ring-2 ring-indigo-200': isFocused,
|
||||||
isFocused && !startAdornment,
|
'border-gray-300': !isError && !isFocused,
|
||||||
'border-base-content/10!': !isError && !isFocused,
|
'bg-gray-100 text-gray-400 cursor-not-allowed': isDisabled,
|
||||||
'bg-gray-100 text-gray-400 cursor-not-allowed':
|
|
||||||
isDisabled && !readOnly,
|
|
||||||
'bg-transparent! cursor-not-allowed!': readOnly,
|
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
valueContainer: () => cn('flex-1 px-3! pr-2! py-2.5! gap-1'),
|
valueContainer: () => cn('flex-1 px-4! py-2! gap-1'),
|
||||||
|
}),
|
||||||
placeholder: () =>
|
placeholder: () =>
|
||||||
cn({
|
cn({ 'text-gray-400': !isError, 'text-red-300!': isError }),
|
||||||
'text-gray-400 text-sm leading-tight': !isError,
|
|
||||||
'text-red-300!': isError,
|
|
||||||
}),
|
|
||||||
singleValue: () =>
|
singleValue: () =>
|
||||||
cn({
|
cn({ 'text-gray-900': !isError, 'text-error!': isError }),
|
||||||
'm-0! text-gray-900 text-sm leading-tight': !isError,
|
input: () => cn('text-gray-900'),
|
||||||
'text-error!': isError,
|
indicatorsContainer: () => cn('flex items-center gap-1 pr-2'),
|
||||||
'text-gray-900!': readOnly,
|
|
||||||
}),
|
|
||||||
input: () => cn('text-gray-900 m-0! p-0! text-sm leading-tight'),
|
|
||||||
indicatorsContainer: () => cn('flex items-center gap-1 pr-3 py-2'),
|
|
||||||
dropdownIndicator: ({ isFocused }) =>
|
dropdownIndicator: ({ isFocused }) =>
|
||||||
cn('p-0! rounded hover:bg-gray-100', {
|
cn('p-1 rounded hover:bg-gray-100', {
|
||||||
'text-gray-900': isFocused,
|
'text-gray-900': isFocused,
|
||||||
'text-gray-500': !isFocused,
|
'text-gray-500': !isFocused,
|
||||||
'text-error!': isError,
|
'text-error!': isError,
|
||||||
}),
|
}),
|
||||||
clearIndicator: () => cn('p-0! rounded hover:bg-gray-100'),
|
|
||||||
menu: () =>
|
menu: () =>
|
||||||
cn(
|
cn('border border-gray-200 rounded! bg-base-100 shadow-lg!'),
|
||||||
'border border-base-content/5 rounded-xl! bg-base-100 shadow-lg! my-1.5!'
|
menuList: () => cn('p-2! max-h-60 overflow-auto'),
|
||||||
),
|
|
||||||
menuList: () => cn('p-0! max-h-60 overflow-auto'),
|
|
||||||
option: ({ isFocused, isSelected }) =>
|
option: ({ isFocused, isSelected }) =>
|
||||||
cn('px-3 py-2 rounded-md cursor-pointer!', {
|
cn('mt-1 px-3 py-2 rounded-md cursor-pointer!', {
|
||||||
'bg-indigo-600 text-white': isFocused,
|
'bg-indigo-600 text-white': isFocused,
|
||||||
'bg-blue-500!': isSelected,
|
'bg-blue-500!': isSelected,
|
||||||
'text-gray-700': !isFocused && !isSelected,
|
'text-gray-700': !isFocused && !isSelected,
|
||||||
@@ -453,23 +244,18 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
|||||||
multiValue: ({ getValue, index }) => {
|
multiValue: ({ getValue, index }) => {
|
||||||
const selectedValues = getValue() as T[];
|
const selectedValues = getValue() as T[];
|
||||||
return cn(
|
return cn(
|
||||||
'bg-base-200! rounded-lg! py-[3px] px-2.5 m-0! flex items-center gap-1! w-fit gap-2!',
|
'bg-indigo-50 rounded py-0.5 pl-2 pr-1 flex items-center gap-1!',
|
||||||
selectedValues[index]?.className
|
selectedValues[index]?.className
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
multiValueRemove: () => cn('p-0! w-3 h-3'),
|
|
||||||
multiValueLabel: ({ getValue, index }) => {
|
multiValueLabel: ({ getValue, index }) => {
|
||||||
const selectedValues = getValue() as T[];
|
const selectedValues = getValue() as T[];
|
||||||
return cn(
|
return cn('text-indigo-700', selectedValues[index]?.labelClassName);
|
||||||
'p-0! text-base-content! text-xs!',
|
|
||||||
selectedValues[index]?.labelClassName
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
components={{
|
components={{
|
||||||
...components,
|
...components,
|
||||||
...(optionComponent ? { Option: optionComponent } : {}),
|
...(optionComponent ? { Option: optionComponent } : {}),
|
||||||
MenuList: CustomMenuList,
|
|
||||||
}}
|
}}
|
||||||
{...(startAdornment && {
|
{...(startAdornment && {
|
||||||
shouldShowAdornment,
|
shouldShowAdornment,
|
||||||
@@ -482,16 +268,8 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
|||||||
}
|
}
|
||||||
styles={{
|
styles={{
|
||||||
menuPortal: (base) => ({ ...base, zIndex: 9999 }),
|
menuPortal: (base) => ({ ...base, zIndex: 9999 }),
|
||||||
multiValue(base) {
|
|
||||||
return {
|
|
||||||
...base,
|
|
||||||
borderRadius: '8px',
|
|
||||||
};
|
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
onMenuScrollToBottom={onMenuScrollToBottom}
|
|
||||||
/>
|
/>
|
||||||
)}
|
|
||||||
|
|
||||||
{isError && <p className='w-full text-sm text-error'>{errorMessage}</p>}
|
{isError && <p className='w-full text-sm text-error'>{errorMessage}</p>}
|
||||||
{!isError && bottomLabel && (
|
{!isError && bottomLabel && (
|
||||||
@@ -502,7 +280,7 @@ const SelectInput = <T extends OptionType>(props: SelectInputProps<T>) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const useSelect = <T,>(
|
const useSelect = <T,>(
|
||||||
basePath: string | null,
|
basePath: string,
|
||||||
valueKey: keyof T | string,
|
valueKey: keyof T | string,
|
||||||
labelKey: keyof T | string,
|
labelKey: keyof T | string,
|
||||||
searchKey: string = 'search',
|
searchKey: string = 'search',
|
||||||
@@ -510,96 +288,34 @@ const useSelect = <T,>(
|
|||||||
) => {
|
) => {
|
||||||
const [inputValue, setInputValue] = useState('');
|
const [inputValue, setInputValue] = useState('');
|
||||||
|
|
||||||
const pageKey = 'page';
|
const optionsUrlParams = useMemo(() => {
|
||||||
const limitKey = 'limit';
|
return new URLSearchParams({
|
||||||
const limit = params?.['limit'] ?? 10;
|
|
||||||
|
|
||||||
const getKey = (
|
|
||||||
pageIndex: number,
|
|
||||||
previousPageData?: BaseApiResponse<T[]>
|
|
||||||
) => {
|
|
||||||
// stop when backend says no more pages
|
|
||||||
if (previousPageData && isResponseSuccess(previousPageData)) {
|
|
||||||
const meta = previousPageData.meta;
|
|
||||||
if (meta && meta.page >= meta.total_pages) return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const qs = new URLSearchParams({
|
|
||||||
...(params ?? {}),
|
|
||||||
[searchKey]: inputValue ?? '',
|
[searchKey]: inputValue ?? '',
|
||||||
[pageKey]: String(pageIndex + 1),
|
...params,
|
||||||
[limitKey]: String(limit),
|
|
||||||
}).toString();
|
}).toString();
|
||||||
|
}, [inputValue, searchKey, params]);
|
||||||
|
|
||||||
return basePath ? `${basePath}?${qs}` : null;
|
const optionsUrl = `${basePath}?${optionsUrlParams}`;
|
||||||
};
|
|
||||||
|
|
||||||
const {
|
const { data, isLoading } = useSWR(optionsUrl, async (url) => {
|
||||||
data: pages,
|
return await httpClientFetcher<BaseApiResponse<T[]>>(url);
|
||||||
isLoading,
|
});
|
||||||
isValidating,
|
|
||||||
size,
|
|
||||||
setSize,
|
|
||||||
} = useSWRInfinite<BaseApiResponse<T[]>>(getKey, (url) =>
|
|
||||||
httpClientFetcher<BaseApiResponse<T[]>>(url)
|
|
||||||
);
|
|
||||||
|
|
||||||
const options = useMemo(() => {
|
const options = isResponseSuccess(data)
|
||||||
if (!pages) return [];
|
? data.data.map((item) => {
|
||||||
|
return {
|
||||||
return pages.flatMap((page) =>
|
|
||||||
isResponseSuccess(page)
|
|
||||||
? page.data.map((item) => ({
|
|
||||||
value: getByPath<T, number>(item, valueKey as string),
|
value: getByPath<T, number>(item, valueKey as string),
|
||||||
label: getByPath<T, string>(item, labelKey as string),
|
label: getByPath<T, string>(item, labelKey as string),
|
||||||
}))
|
|
||||||
: []
|
|
||||||
);
|
|
||||||
}, [pages, valueKey, labelKey]);
|
|
||||||
|
|
||||||
const lastPage = pages?.[pages.length - 1];
|
|
||||||
const hasMore =
|
|
||||||
!!lastPage &&
|
|
||||||
isResponseSuccess(lastPage) &&
|
|
||||||
!!lastPage.meta &&
|
|
||||||
lastPage.meta.page < lastPage.meta.total_pages;
|
|
||||||
|
|
||||||
const loadMore = () => {
|
|
||||||
if (!hasMore) return;
|
|
||||||
setSize(size + 1);
|
|
||||||
};
|
};
|
||||||
|
})
|
||||||
let formattedSuccessRawData: SuccessApiResponse<T[]> | undefined = undefined;
|
: [];
|
||||||
let formattedErrorRawData: ErrorApiResponse | undefined = undefined;
|
|
||||||
|
|
||||||
const latestPagesIndex = pages?.length ? pages.length - 1 : 0;
|
|
||||||
|
|
||||||
if (isResponseSuccess(pages?.[latestPagesIndex])) {
|
|
||||||
formattedSuccessRawData = {
|
|
||||||
...pages?.[latestPagesIndex],
|
|
||||||
data:
|
|
||||||
pages?.flatMap((page) => (isResponseSuccess(page) ? page.data : [])) ??
|
|
||||||
[],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isResponseError(pages?.[latestPagesIndex])) {
|
|
||||||
formattedErrorRawData = pages?.[latestPagesIndex];
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
inputValue,
|
inputValue,
|
||||||
setInputValue,
|
setInputValue,
|
||||||
|
|
||||||
options,
|
options,
|
||||||
rawData: isResponseSuccess(pages?.[latestPagesIndex])
|
isLoadingOptions: isLoading,
|
||||||
? formattedSuccessRawData
|
rawData: data,
|
||||||
: formattedErrorRawData,
|
|
||||||
|
|
||||||
isLoadingOptions: isLoading || isValidating,
|
|
||||||
isLoadingMore: isValidating && size > 1,
|
|
||||||
hasMore,
|
|
||||||
loadMore,
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user