From 7e67f5f8287ecc43a1c73f7dd95f3b7413e67019 Mon Sep 17 00:00:00 2001 From: fro1991 Date: Sat, 1 Feb 2025 19:53:11 +0700 Subject: [PATCH] update --- .../home/hooks/useFetchCardData.tsx | 2 +- .../home/hooks/useFetchChartData.tsx | 2 +- .../dashboards/home/hooks/useFetchYear.tsx | 2 +- src/pages/instansi/InstansiPage.tsx | 20 - src/pages/instansi/blocks/AddDialog.tsx | 262 --------- src/pages/instansi/blocks/DeleteDialog.tsx | 75 --- src/pages/instansi/blocks/EditDialog.tsx | 275 --------- src/pages/instansi/blocks/ListToolBar.tsx | 96 ---- src/pages/instansi/blocks/index.ts | 3 - src/pages/instansi/components/AlertCrud.tsx | 93 --- src/pages/instansi/hooks/InstansiContext.tsx | 223 -------- src/pages/instansi/hooks/index.ts | 2 - .../instansi/hooks/useInstansiContext.tsx | 12 - src/pages/instansi/index.ts | 1 - .../chart/CreditChartPage.tsx | 189 ------- .../pengajuan_kredit/chart/blocks/Chart.tsx | 193 ------- .../chart/blocks/DateRangePicker.tsx | 74 --- .../chart/blocks/YearPicker.tsx | 92 --- .../pengajuan_kredit/chart/blocks/index.ts | 3 - .../chart/hooks/CreditChartContext.tsx | 17 - .../pengajuan_kredit/chart/hooks/index.ts | 3 - .../chart/hooks/useCreditChartContext.tsx | 11 - .../chart/hooks/useFetchCreditChartData.tsx | 53 -- src/pages/pengajuan_kredit/chart/index.ts | 1 - .../pengajuan_kredit/list/CreditAddPage.tsx | 12 - .../list/CreditDetailPage.tsx | 12 - .../pengajuan_kredit/list/CreditListPage.tsx | 14 - .../list/blocks/ChatMessageIn.tsx | 22 - .../list/blocks/ChatMessageOut.tsx | 27 - .../list/blocks/DatePicker.tsx | 58 -- .../list/blocks/DateRangePicker.tsx | 60 -- .../list/blocks/ListToolBar.tsx | 293 ---------- .../pengajuan_kredit/list/blocks/Notes.tsx | 49 -- .../pengajuan_kredit/list/blocks/index.ts | 6 - .../list/hooks/CreditAddContext.tsx | 215 ------- .../list/hooks/CreditDetailContext.tsx | 532 ------------------ .../list/hooks/CreditDetailContext.tsx.bak | 379 ------------- .../list/hooks/CreditListContext.tsx | 329 ----------- .../pengajuan_kredit/list/hooks/index.ts | 7 - .../list/hooks/useCreditAddContext.tsx | 12 - .../list/hooks/useCreditDetailContext.tsx | 12 - .../list/hooks/useCreditListContext.tsx | 12 - .../list/hooks/useCreditUpdateData.tsx | 61 -- src/pages/pengajuan_kredit/list/index.ts | 3 - .../pengajuan_kredit/list/steps/StepFour.tsx | 104 ---- .../pengajuan_kredit/list/steps/StepOne.tsx | 252 --------- .../pengajuan_kredit/list/steps/StepThree.tsx | 133 ----- .../pengajuan_kredit/list/steps/StepTwo.tsx | 377 ------------- .../pengajuan_kredit/list/steps/index.ts | 4 - .../summary/CreditSummaryPage.tsx | 224 -------- .../summary/blocks/DateRangePicker.tsx | 74 --- .../summary/blocks/DetailDialog.tsx | 333 ----------- .../pengajuan_kredit/summary/blocks/List.tsx | 133 ----- .../summary/blocks/ListToolBar.tsx | 15 - .../pengajuan_kredit/summary/blocks/index.ts | 4 - .../summary/hooks/CreditSummaryContext.tsx | 60 -- .../pengajuan_kredit/summary/hooks/index.ts | 3 - .../summary/hooks/useCreditSummaryContext.tsx | 12 - .../hooks/useFetchCreditSummaryData.tsx | 56 -- src/pages/pengajuan_kredit/summary/index.ts | 1 - src/routing/AppRoutingSetup.tsx | 8 - 61 files changed, 3 insertions(+), 5609 deletions(-) delete mode 100644 src/pages/instansi/InstansiPage.tsx delete mode 100644 src/pages/instansi/blocks/AddDialog.tsx delete mode 100644 src/pages/instansi/blocks/DeleteDialog.tsx delete mode 100644 src/pages/instansi/blocks/EditDialog.tsx delete mode 100644 src/pages/instansi/blocks/ListToolBar.tsx delete mode 100644 src/pages/instansi/blocks/index.ts delete mode 100644 src/pages/instansi/components/AlertCrud.tsx delete mode 100644 src/pages/instansi/hooks/InstansiContext.tsx delete mode 100644 src/pages/instansi/hooks/index.ts delete mode 100644 src/pages/instansi/hooks/useInstansiContext.tsx delete mode 100644 src/pages/instansi/index.ts delete mode 100644 src/pages/pengajuan_kredit/chart/CreditChartPage.tsx delete mode 100644 src/pages/pengajuan_kredit/chart/blocks/Chart.tsx delete mode 100644 src/pages/pengajuan_kredit/chart/blocks/DateRangePicker.tsx delete mode 100644 src/pages/pengajuan_kredit/chart/blocks/YearPicker.tsx delete mode 100644 src/pages/pengajuan_kredit/chart/blocks/index.ts delete mode 100644 src/pages/pengajuan_kredit/chart/hooks/CreditChartContext.tsx delete mode 100644 src/pages/pengajuan_kredit/chart/hooks/index.ts delete mode 100644 src/pages/pengajuan_kredit/chart/hooks/useCreditChartContext.tsx delete mode 100644 src/pages/pengajuan_kredit/chart/hooks/useFetchCreditChartData.tsx delete mode 100644 src/pages/pengajuan_kredit/chart/index.ts delete mode 100644 src/pages/pengajuan_kredit/list/CreditAddPage.tsx delete mode 100644 src/pages/pengajuan_kredit/list/CreditDetailPage.tsx delete mode 100644 src/pages/pengajuan_kredit/list/CreditListPage.tsx delete mode 100644 src/pages/pengajuan_kredit/list/blocks/ChatMessageIn.tsx delete mode 100644 src/pages/pengajuan_kredit/list/blocks/ChatMessageOut.tsx delete mode 100644 src/pages/pengajuan_kredit/list/blocks/DatePicker.tsx delete mode 100644 src/pages/pengajuan_kredit/list/blocks/DateRangePicker.tsx delete mode 100644 src/pages/pengajuan_kredit/list/blocks/ListToolBar.tsx delete mode 100644 src/pages/pengajuan_kredit/list/blocks/Notes.tsx delete mode 100644 src/pages/pengajuan_kredit/list/blocks/index.ts delete mode 100644 src/pages/pengajuan_kredit/list/hooks/CreditAddContext.tsx delete mode 100644 src/pages/pengajuan_kredit/list/hooks/CreditDetailContext.tsx delete mode 100644 src/pages/pengajuan_kredit/list/hooks/CreditDetailContext.tsx.bak delete mode 100644 src/pages/pengajuan_kredit/list/hooks/CreditListContext.tsx delete mode 100644 src/pages/pengajuan_kredit/list/hooks/index.ts delete mode 100644 src/pages/pengajuan_kredit/list/hooks/useCreditAddContext.tsx delete mode 100644 src/pages/pengajuan_kredit/list/hooks/useCreditDetailContext.tsx delete mode 100644 src/pages/pengajuan_kredit/list/hooks/useCreditListContext.tsx delete mode 100644 src/pages/pengajuan_kredit/list/hooks/useCreditUpdateData.tsx delete mode 100644 src/pages/pengajuan_kredit/list/index.ts delete mode 100644 src/pages/pengajuan_kredit/list/steps/StepFour.tsx delete mode 100644 src/pages/pengajuan_kredit/list/steps/StepOne.tsx delete mode 100644 src/pages/pengajuan_kredit/list/steps/StepThree.tsx delete mode 100644 src/pages/pengajuan_kredit/list/steps/StepTwo.tsx delete mode 100644 src/pages/pengajuan_kredit/list/steps/index.ts delete mode 100644 src/pages/pengajuan_kredit/summary/CreditSummaryPage.tsx delete mode 100644 src/pages/pengajuan_kredit/summary/blocks/DateRangePicker.tsx delete mode 100644 src/pages/pengajuan_kredit/summary/blocks/DetailDialog.tsx delete mode 100644 src/pages/pengajuan_kredit/summary/blocks/List.tsx delete mode 100644 src/pages/pengajuan_kredit/summary/blocks/ListToolBar.tsx delete mode 100644 src/pages/pengajuan_kredit/summary/blocks/index.ts delete mode 100644 src/pages/pengajuan_kredit/summary/hooks/CreditSummaryContext.tsx delete mode 100644 src/pages/pengajuan_kredit/summary/hooks/index.ts delete mode 100644 src/pages/pengajuan_kredit/summary/hooks/useCreditSummaryContext.tsx delete mode 100644 src/pages/pengajuan_kredit/summary/hooks/useFetchCreditSummaryData.tsx delete mode 100644 src/pages/pengajuan_kredit/summary/index.ts diff --git a/src/pages/dashboards/home/hooks/useFetchCardData.tsx b/src/pages/dashboards/home/hooks/useFetchCardData.tsx index 0789ed8..df26310 100644 --- a/src/pages/dashboards/home/hooks/useFetchCardData.tsx +++ b/src/pages/dashboards/home/hooks/useFetchCardData.tsx @@ -4,7 +4,7 @@ import { DateRange } from 'react-day-picker'; import { formatDate } from 'date-fns'; import { apiConfig } from '@/config/api.config'; -const API_URL = apiConfig.service_credit; +const API_URL = apiConfig.service_dashboard; interface UseFetchCardDataResult { cardData: any; diff --git a/src/pages/dashboards/home/hooks/useFetchChartData.tsx b/src/pages/dashboards/home/hooks/useFetchChartData.tsx index 6647d43..2b18204 100644 --- a/src/pages/dashboards/home/hooks/useFetchChartData.tsx +++ b/src/pages/dashboards/home/hooks/useFetchChartData.tsx @@ -4,7 +4,7 @@ import { DateRange } from 'react-day-picker'; import { formatDate } from 'date-fns'; import { apiConfig } from '@/config/api.config'; -const API_URL = apiConfig.service_credit; +const API_URL = apiConfig.service_dashboard; interface UseFetchChartDataResult { chartData: any[]; diff --git a/src/pages/dashboards/home/hooks/useFetchYear.tsx b/src/pages/dashboards/home/hooks/useFetchYear.tsx index a134e8a..426c145 100644 --- a/src/pages/dashboards/home/hooks/useFetchYear.tsx +++ b/src/pages/dashboards/home/hooks/useFetchYear.tsx @@ -2,7 +2,7 @@ import { useState, useEffect } from 'react'; import axios from 'axios'; import { apiConfig } from '@/config/api.config'; -const API_URL = apiConfig.service_credit; +const API_URL = apiConfig.service_dashboard; interface YearData { year: string; diff --git a/src/pages/instansi/InstansiPage.tsx b/src/pages/instansi/InstansiPage.tsx deleted file mode 100644 index 74a0ec6..0000000 --- a/src/pages/instansi/InstansiPage.tsx +++ /dev/null @@ -1,20 +0,0 @@ -import { Container, DataGridInner } from '@/components'; -import { EditDialog } from './blocks'; -import { InstansiContextProvider } from './hooks'; -import { AddDialog } from './blocks/AddDialog'; -import { DeleteDialog } from './blocks/DeleteDialog'; - -export default function InstansiPage() { - return ( - - -
- -
- - - -
-
- ); -} diff --git a/src/pages/instansi/blocks/AddDialog.tsx b/src/pages/instansi/blocks/AddDialog.tsx deleted file mode 100644 index 574049b..0000000 --- a/src/pages/instansi/blocks/AddDialog.tsx +++ /dev/null @@ -1,262 +0,0 @@ -import { useCallback, useEffect, useRef, useState } from 'react'; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue -} from '@/components/ui/select'; - -import { - Dialog, - DialogBody, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle -} from '@/components/ui/dialog'; -import { useInstansiContext } from '../hooks'; -import { Input } from '@/components/ui/input'; -import { Button } from '@/components/ui/button'; -import { apiConfig } from '@/config/api.config'; -import { Alert, KeenIcon, useDataGrid } from '@/components'; -import { toast } from 'sonner'; -import { useCallApi } from '@/hooks'; -import { doSaveLogActivity } from '@/actions/GlobalActions'; -import { Textarea } from '@/components/ui/textarea'; - -const API_URL = apiConfig.service_credit; - -const AddDialog = () => { - const parentRef = useRef(null); - const { showAddDialog, handleAddDialog } = useInstansiContext(); - const { reload } = useDataGrid(); - const { PostData } = useCallApi(); - const [alert, setAlert] = useState({ - show: false, - message: '' - }); - - const initialState = { - name: '', - code: '', - description: '', - type: '', - pic_name: '', - pic_email: '', - pic_phone: '', - status: '' - }; - - const [formField, setFormField] = useState(initialState); - - const resetForm = () => { - setFormField(initialState); - }; - /* actions */ - const doCreate = useCallback( - async (e: React.FormEvent) => { - e.preventDefault(); - const response = await PostData(`${API_URL}/company/create`, formField); - if (response?.status) { - setAlert((prev) => ({ ...prev, show: false, message: '' })); - handleAddDialog(false); - toast.success('Success Create Insansi'); - reload(); - const createActivity = { - module: 'Instansi', - description: `Add Insansi => ${formField.name}`, - action: 'C' - }; - - doSaveLogActivity(createActivity); - - resetForm(); - } else { - setAlert((prev) => ({ ...prev, show: true, message: response?.message })); - } - }, - [formField] - ); - - return ( - handleAddDialog(open)}> - - - - -
-
-

Tambah Instansi

-
-
- -
-
- -
- {alert.show && ( - -

{alert.message}

-
- )} -
-
-

Instansi Information

-
-
-
-
- - - setFormField((prev) => ({ ...prev, name: target.value })) - } - /> -
-
-
-
- - - setFormField((prev) => ({ ...prev, code: target.value })) - } - /> -
-
-
-
-
- -
- -
-
-
-
-
- - - - )} -
-
-
-
-
-
-
-

Debitur Document's

-
-
-

- {toCamelCase(data?.debtor?.identity_type) || 'Loading...'} -

-
- {data?.debtor?.identity_file && - DivImageAction( - data?.debtor?.identity_file, - data.debtor?.identity_file_status, - (newStatus) => handleSelectChange(newStatus, 'identity_file_status', true) - )} -
-
-
-

Kartu Keluarga (Vica Familia)

-
- {data?.debtor?.family_file && - DivImageAction( - data?.debtor?.family_file, - data.debtor.family_file_status, - (newStatus) => handleSelectChange(newStatus, 'family_file_status', true) - )} -
-
-
-

{data?.debtor?.marriage_type || 'Loading...'}

-
- {data?.debtor?.marriage_file && - DivImageAction( - data?.debtor?.marriage_file, - data.debtor.marriage_file_status, - (newStatus) => handleSelectChange(newStatus, 'marriage_file_status', true) - )} -
-
- {data?.debtor?.photo && ( -
-

Photo

-
- {data?.debtor?.photo && - DivImageAction( - data?.debtor?.photo, // - data?.debtor?.photo_status, - (newStatus) => handleSelectChange(newStatus, 'photo_status', true) - )} -
-
- )} - {data?.debtor?.spouse_photo && ( -
-

Spouse ({data?.debtor?.spouse_type}) Photo

-
- {data?.debtor?.spouse_photo && - DivImageAction( - data?.debtor?.spouse_photo, // - data?.debtor?.spouse_photo_status, - (newStatus) => handleSelectChange(newStatus, 'spouse_photo_status', true) - )} -
-
- )} - {data?.debtor?.spouse_type && ( -
-

- Spouse ({data?.debtor?.spouse_type}) {data?.debtor?.spouse_file_type} -

-
- {data?.debtor?.spouse_file && - DivImageAction( - data?.debtor?.spouse_file, // - data?.debtor?.spouse_file_status, - (newStatus) => handleSelectChange(newStatus, 'spouse_file_status', true) - )} -
-
- )} -
-
-
-
-

Supporting Document's

-
- {data?.form?.map( - (item: { label: string; value: string; status: string }, index: any) => ( -
-

{item.label}

-
- {item.value && - DivImageAction( - item.value, - item.status, - (newStatus) => handleSelectChange(newStatus, 'status', false, index) // Menambahkan index - )} -
-
- ) - )} -
-
-
-
- {data?.status === 'under_review' && ( -
-
- -
-
-
- -
-
-
- )} - - ); -}; - -export { CreditDetailContext, CreditDetailContextProvider }; diff --git a/src/pages/pengajuan_kredit/list/hooks/CreditDetailContext.tsx.bak b/src/pages/pengajuan_kredit/list/hooks/CreditDetailContext.tsx.bak deleted file mode 100644 index 937616a..0000000 --- a/src/pages/pengajuan_kredit/list/hooks/CreditDetailContext.tsx.bak +++ /dev/null @@ -1,379 +0,0 @@ -import { useLocation } from 'react-router-dom'; -import { useLanguage } from '@/i18n'; -import axios from 'axios'; -import { fCurrency } from '@/utils/FormatNumber'; -import { DefaultTooltip, KeenIcon } from '@/components'; -import { Button } from '@/components/ui/button'; -import { useNavigate } from 'react-router-dom'; -import { createContext, useEffect, useState } from 'react'; -import { apiConfig } from '@/config/api.config'; -import moment from 'moment'; - -import { - statusCreditList, - toCamelCase, - toAbsoluteUrl, - ApplicationFileDownloadUrl, - getFileExtension, - snakeToTitleCase -} from '@/utils'; - -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue -} from '@/components/ui/select'; -import { useAuthContext } from '@/auth'; -import { ChatMessageIn, ChatMessageOut, Notes } from '../blocks'; -import { Textarea } from '@/components/ui/textarea'; - -const API_URL = apiConfig.service_credit; -const CreditDetailContext = createContext(null); - -const CreditDetailContextProvider = ({ children }: { children: React.ReactNode }) => { - const navigate = useNavigate(); - const [data, setData] = useState({}); - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); - const { isRTL } = useLanguage(); - const { state } = useLocation(); - const { id, code, status } = state || {}; - const { auth } = useAuthContext(); - - const handleBackClick = () => { - navigate('/pengajuan_kredit/list'); - }; - - useEffect(() => { - const fetchData = async () => { - if (!id) return; - setIsLoading(true); - setError(null); - try { - const response = await axios.get(`${API_URL}/application/detail/${id}`); - setData(response.data.data || {}); - console.log('data:', data.form); - } catch (err) { - setError('Failed to fetch data'); - } finally { - setIsLoading(false); - } - }; - - fetchData(); - }, [id]); - - const DivImageAction = ( - fileName: string, - fileStatus: string, - onChange: (value: string) => void - ) => ( - <> - - - - - - - ); - - if (isLoading) { - return
Fetching data...
; - } - - if (error) { - return
{error}
; - } - - return ( -
-
-
- - - -

{code}

-
-
- -
-
-
-
-

Credit Request

-
-
-

BRI Account Number

-

- {data?.account_number || 'Loading...'} -

-
-
-

Amount

-

- {fCurrency(data?.amount) || 'Loading...'} -

-
-
-

Period

-

- {data?.period_amount} {toCamelCase(data?.period_type) || 'Loading...'} -

-
- -
-

Status

-

- {snakeToTitleCase(data?.status) || 'Loading...'} -

-
-
-
-
-
-

Debitur Info's

-
-
-

Application Date

-

- {moment(data?.application_date).format('dddd, MMMM DD, YYYY') || 'Loading...'} -

-
-
-

Company

-

- {data?.company?.name || 'Loading...'} -

-
-
-

Employee Id

-

- {data?.debtor?.employee_id || 'Loading...'} -

-
-
-

Name

-

- {data?.debtor?.name || 'Loading...'} -

-
-
-

Phone Number

-

- {data?.debtor?.phone || 'Loading...'} -

-
-
-

Type

-

- {toCamelCase(data?.debtor?.type) || 'Loading...'} -

-
-
-

Mariage

-

- {data?.debtor?.marriage_type || 'Loading...'} -

-
-
-
-
-
-

Note's

-
-
- {data?.chat - ?.sort( - (a: any, b: any) => - new Date(a.created_at).getTime() - new Date(b.created_at).getTime() - ) - .map( - ( - message: { - name: string; - company: string; - message: string; - created_at: string; - }, - index: number - ) => ( - - ) - )} - - -
-
-
-
-
-
-
-

Debitur Document's

-
-
-

- {toCamelCase(data?.debtor?.identity_type) || 'Loading...'} -

-
- {data?.debtor?.identity_file && - DivImageAction( - data?.debtor?.identity_file, - data.debtor.identity_file_status, - () => {} - )} -
-
-
-

Kartu Keluarga (Vica Familia)

-
- {data?.debtor?.family_file && - DivImageAction( - data?.debtor?.family_file, - data?.debtor?.family_file_status, - () => {} - )} -
-
-
-

{data?.debtor?.marriage_type || 'Loading...'}

-
- {data?.debtor?.marriage_file && - DivImageAction( - data?.debtor?.marriage_file, - data?.debtor?.marriage_file_status, - () => {} - )} -
-
- {data?.debtor?.photo && ( -
-

Photo

-
- {data?.debtor?.photo && - DivImageAction( - data?.debtor?.photo, // - data?.debtor?.photo_status, - () => {} - )} -
-
- )} - {data?.debtor?.spouse_photo && ( -
-

Spouse ({data?.debtor?.spouse_type}) Photo

-
- {data?.debtor?.spouse_photo && - DivImageAction( - data?.debtor?.spouse_photo, // - data?.debtor?.spouse_photo_status, - () => {} - )} -
-
- )} - {data?.debtor?.spouse_type && ( -
-

- Spouse ({data?.debtor?.spouse_type}) {data?.debtor?.spouse_file_type} -

-
- {data?.debtor?.spouse_file && - DivImageAction( - data?.debtor?.spouse_file, // - data?.debtor?.spouse_file_status, - () => {} - )} -
-
- )} -
-
-
-
-

Supporting Document's

-
- {data?.form?.map( - (item: { label: string; value: string; status: string }, index: any) => ( -
-

{item.label}

-
- {item.value && DivImageAction(item.value, item.status, () => {})} -
-
- ) - )} -
-
-
-
- -
-
- -
-
- -
-
-
- ); -}; - -export { CreditDetailContext, CreditDetailContextProvider }; diff --git a/src/pages/pengajuan_kredit/list/hooks/CreditListContext.tsx b/src/pages/pengajuan_kredit/list/hooks/CreditListContext.tsx deleted file mode 100644 index 0106e29..0000000 --- a/src/pages/pengajuan_kredit/list/hooks/CreditListContext.tsx +++ /dev/null @@ -1,329 +0,0 @@ -import { doSaveLogActivity } from '@/actions/GlobalActions'; -import { DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components'; -import { Toaster } from '@/components/ui/sonner'; -import { apiConfig } from '@/config/api.config'; -import { useCallApi } from '@/hooks'; -import { fCurrency } from '@/utils/FormatNumber'; -import { ColumnDef } from '@tanstack/react-table'; -import { addDays, format } from 'date-fns'; -import moment from 'moment'; -import React, { createContext, useMemo, useState } from 'react'; -import { DateRange } from 'react-day-picker'; -import { ListToolBar } from '../blocks/ListToolBar'; -// import { CardList } from '../blocks'; - -import { getAuth } from '@/auth'; -import { useNavigate } from 'react-router'; -import { snakeToTitleCase, toCamelCase } from '@/utils'; - -interface ContextProps { - date: DateRange | undefined; - setDate: (date: DateRange | undefined) => void; - doExportData: (sorting: any, filter: any) => Promise; -} - -const initialProps: ContextProps = { - date: undefined, - setDate: () => {}, - doExportData: async () => ({ data: [], totalCount: 0 }) -}; - -const CreditListContext = createContext(initialProps); - -const API_URL = apiConfig.service_credit; - -const CreditListContextProvider = ({ children }: { children: React.ReactNode }) => { - /* state */ - const { GetData } = useCallApi(); - const { GetExportData } = useCallApi(); - const [date, setDate] = useState({ - from: new Date(new Date().setDate(new Date().getDate() - 31)), - to: new Date() - }); - - const navigate = useNavigate(); - - /* Data Grid Options */ - const columns = useMemo[]>( - () => [ - { - accessorFn: (row) => row.application_date, - id: 'application_date', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-1/12 text-center', - cellClassName: 'text-center' - } - }, - { - accessorFn: (row) => row.code, - id: 'code', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-1/12' - } - }, - { - accessorFn: (row) => row.company.name, - id: 'company.name', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-2/12' - } - }, - { - accessorFn: (row) => row.debtor.name, - id: 'debtor.name', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-3/12' - } - }, - { - accessorFn: (row) => row.debtor.employee_id, - id: 'debtor.employee_id', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-1/12' - } - }, - { - accessorFn: (row) => row.amount, - id: 'amount', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-1/12 text-end', - cellClassName: 'text-end' - }, - cell: (data: any) => fCurrency(data.row.original.amount) - }, - { - accessorFn: (row) => row.period, - id: 'period', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-1/12 text-center', - cellClassName: 'text-center' - }, - cell: (data: any) => { - const row = data.row.original; - return ( - <> -

- {data.row.original.period_amount} {toCamelCase(data.row.original.period_type)} -

- - ); - } - }, - { - accessorFn: (row) => row.status, - id: 'status', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-1/12 text-center', - cellClassName: 'text-center' - }, - cell: (data: any) => String(snakeToTitleCase(data.row.original.status)).toUpperCase() - }, - { - accessorFn: (row) => row.finalize_by, - id: 'finalize_by', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-1/12 text-center', - cellClassName: 'text-center' - }, - cell: (data: any) => { - const row = data.row.original; - return ( - <> -

{String(snakeToTitleCase(data.row.original.finalize_by || '')).toUpperCase()}

-

- - {data.row.original.finalize_by && - moment(data.row.original.update_at).format('DD-MM-YYYY HH:mm:ss')} - -

- - ); - } - }, - // { - // accessorFn: (row) => row.finalize_by, - // id: 'finalize_by', - // header: ({ column }) => , - // enableSorting: false, - // enableHiding: false, - // meta: { - // headerClassName: 'w-2/12 text-center', - // cellClassName: 'text-center' - // }, - // cell: (data: any) => - // data.row.original.finalize_by && - // moment(data.row.original.update_at).format('DD-MM-YYYY HH:mm:ss') - // }, - { - id: 'actions', - enableSorting: false, - enableHiding: false, - header: ({ column }) => ( - - ), - cell: (data: any) => { - const row = data.row.original; - return ( - <> - - - ); - }, - meta: { - cellClassName: 'text-center' - } - } - ], - [] - ); - - const doGetListData = async (page: number, limit: number, sorting: any, filter: any) => { - sorting = sorting.length === 0 ? [{ id: 'created_at', desc: false }] : sorting; - - filter = filter?.length === 0 ? {} : filter; - let filterObject: Record = {}; - if (Object.keys(filter).length !== 0) { - for (let _filter of filter) { - filterObject[_filter.id] = _filter.value; - } - } - - filter = filterObject; - - const startDate = date?.from - ? format(date.from, 'yyyy-MM-dd') - : format(new Date(new Date().setDate(new Date().getDate() - 30)), 'yyyy-MM-dd'); - // const endDate = date?.to ? format(date.to, 'yyyy-MM-dd') : format(new Date(), 'yyyy-MM-dd'); - const endDate = date?.to - ? format(addDays(date.to, 1), 'yyyy-MM-dd') - : format(addDays(new Date(), 1), 'yyyy-MM-dd'); - - const response = await GetData(`${API_URL}/application/list`, { - limit: limit, - page: page + 1, - with_deleted: false, - order_field: sorting[0].id, - order_direction: sorting[0].desc == false ? 'ASC' : 'DESC', - filter: JSON.stringify({ - ...filter, - application_date_from: startDate, - application_date_to: endDate - }) - }); - - return { data: response?.data.list, totalCount: response?.data.total_count }; - }; - - const doExportData = async (sorting: any, filter: any) => { - sorting = sorting.length === 0 ? [{ id: 'created_at', desc: false }] : sorting; - - const startDate = date?.from - ? format(date.from, 'yyyy-MM-dd') - : format(new Date(2024, 5, 1), 'yyyy-MM-dd'); - - const endDate = date?.to ? format(date.to, 'yyyy-MM-dd') : format(new Date(), 'yyyy-MM-dd'); - - const filterObject: Record = {}; - if (filter && Array.isArray(filter)) { - filter.forEach((f: { id: string; value: string }) => { - if (f?.id && f?.value) { - filterObject[f.id] = f.value; - } - }); - } - - const filtes = { - ...filterObject, - application_date_from: startDate, - application_date_to: endDate - }; - - let param = { - with_deleted: false, - order_field: sorting[0].id, - order_direction: sorting[0].desc === false ? 'ASC' : 'DESC', - filter: JSON.stringify(filtes), - token: await getAuth()?.access_token - }; - let url = `${API_URL}/application/list/export`; - const blob = await GetExportData(url, param, 'pengajuan_kredit_export_'); - - if (!(blob instanceof Blob)) { - throw new Error('Failed to export data. Invalid response format.'); - } - - const user = localStorage.getItem('user'); - const parsedUser = user ? JSON.parse(user) : null; - - const createActivity = { - module: 'List Pengajuan Kredit', - description: `Export List Pengajuan Kredit => ${parsedUser ? parsedUser.name : 'Unknown User'}`, - action: 'E' - }; - - doSaveLogActivity(createActivity); - }; - - return ( - - - } - layout={{ card: true }} - sorting={[{ id: 'created_at', desc: false }]} - serverSide={true} - onFetchData={({ pageIndex, pageSize, sorting, columnFilters }) => - doGetListData(pageIndex, pageSize, sorting, columnFilters) - } - > - {children} - - - ); -}; - -export { CreditListContext, CreditListContextProvider }; diff --git a/src/pages/pengajuan_kredit/list/hooks/index.ts b/src/pages/pengajuan_kredit/list/hooks/index.ts deleted file mode 100644 index 200fb9e..0000000 --- a/src/pages/pengajuan_kredit/list/hooks/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -export * from './CreditListContext'; -export * from './CreditDetailContext'; -export * from './CreditAddContext'; -export * from './useCreditListContext'; -export * from './useCreditDetailContext'; -export * from './useCreditAddContext'; -export * from './useCreditUpdateData'; diff --git a/src/pages/pengajuan_kredit/list/hooks/useCreditAddContext.tsx b/src/pages/pengajuan_kredit/list/hooks/useCreditAddContext.tsx deleted file mode 100644 index ac5a6f1..0000000 --- a/src/pages/pengajuan_kredit/list/hooks/useCreditAddContext.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { useContext } from 'react'; -import { CreditAddContext } from './CreditAddContext'; - -const useCreditAddContext = () => { - const context = useContext(CreditAddContext); - - if (!context) throw new Error('useCreditAddContext must be used within AuthProvider'); - - return context; -}; - -export { useCreditAddContext }; diff --git a/src/pages/pengajuan_kredit/list/hooks/useCreditDetailContext.tsx b/src/pages/pengajuan_kredit/list/hooks/useCreditDetailContext.tsx deleted file mode 100644 index bbc7455..0000000 --- a/src/pages/pengajuan_kredit/list/hooks/useCreditDetailContext.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { useContext } from 'react'; -import { CreditDetailContext } from './CreditDetailContext'; - -const useCreditDetailContext = () => { - const context = useContext(CreditDetailContext); - - if (!context) throw new Error('useCreditDetailContext must be used within AuthProvider'); - - return context; -}; - -export { useCreditDetailContext }; diff --git a/src/pages/pengajuan_kredit/list/hooks/useCreditListContext.tsx b/src/pages/pengajuan_kredit/list/hooks/useCreditListContext.tsx deleted file mode 100644 index 343e7e4..0000000 --- a/src/pages/pengajuan_kredit/list/hooks/useCreditListContext.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { useContext } from 'react'; -import { CreditListContext } from './CreditListContext'; - -const useCreditListContext = () => { - const context = useContext(CreditListContext); - - if (!context) throw new Error('useCreditListContext must be used within AuthProvider'); - - return context; -}; - -export { useCreditListContext }; diff --git a/src/pages/pengajuan_kredit/list/hooks/useCreditUpdateData.tsx b/src/pages/pengajuan_kredit/list/hooks/useCreditUpdateData.tsx deleted file mode 100644 index 7daca7f..0000000 --- a/src/pages/pengajuan_kredit/list/hooks/useCreditUpdateData.tsx +++ /dev/null @@ -1,61 +0,0 @@ -import { useState, useEffect, useCallback } from 'react'; -import axios from 'axios'; -import { DateRange } from 'react-day-picker'; -import { formatDate } from 'date-fns'; -import { apiConfig } from '@/config/api.config'; - -const API_URL = apiConfig.service_credit; - -interface useCreditUpdateDataResult { - cardData: any; - isCardLoading: boolean; - cardError: any; -} - -const useCreditUpdateData = (data: any, isOpenUnder: boolean): any => { - const [cardData, setCardData] = useState<[]>([]); - const [responseData, setResponseData] = useState(null); - const updateData = useCallback(async () => { - let dtUpdate = { - name: data.deptor.name, - employee_id: data.deptor.employe_id, - phone: data.deptop.phone, - identity_type: data.deptor.identity_type, - identity_file: data.deptor.identity_file, - identity_file_status: data.deptor.identity_file_status, - type: data.deptor.type, - marriage_type: data.deptor.marriage_type, - marriage_file: data.deptor.marriage_file, - marriage_file_status: data.deptor.marriage_file_status, - family_file: data.deptor.family_file, - family_file_status: data.deptor.family_file_status, - spouse_type: data.deptor.spouse_type, - spouse_file_type: data.deptor.spouse_file_type, - spouse_file: data.deptor.spouse_file, - spouse_file_status: data.deptor.spouse_file_status, - photo: data.deptor.photo, - photo_status: data.deptor.photo_status, - spouse_photo: data.deptor.spouse_photo, - spouse_photo_status: data.deptor.spouse_photo_status, - description: data.deptor.description, - form: data.form, - account_number: data.account_number, - amount: data.amount, - period_type: data.period_type, - period_amount: data.period_amount, - application_date: data.application_date, - companyId: data.companyId, - chat: isOpenUnder ? '' : data.chat, - status: data.status - }; - const response = await axios.put(`${API_URL}/application/update/${data.id}`, { dtUpdate }); - setResponseData(response.data.data); - }, [data, isOpenUnder]); - useEffect(() => { - updateData(); - }, [updateData]); - - return { doUpdate: updateData }; -}; - -export { useCreditUpdateData }; diff --git a/src/pages/pengajuan_kredit/list/index.ts b/src/pages/pengajuan_kredit/list/index.ts deleted file mode 100644 index 9823c0b..0000000 --- a/src/pages/pengajuan_kredit/list/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './CreditListPage'; -export * from './CreditDetailPage'; -export * from './CreditAddPage'; diff --git a/src/pages/pengajuan_kredit/list/steps/StepFour.tsx b/src/pages/pengajuan_kredit/list/steps/StepFour.tsx deleted file mode 100644 index e90b70d..0000000 --- a/src/pages/pengajuan_kredit/list/steps/StepFour.tsx +++ /dev/null @@ -1,104 +0,0 @@ -import { useState } from 'react'; -import { Input } from '@/components/ui/input'; -import { IImageInputFile } from '@/components/image-input'; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue -} from '@/components/ui/select'; - -const StepFour = ({ setFormData, formData }: any) => { - const [tanggalBuka, setTanggalBuka] = useState(new Date()); - const [imageFiles, setImageFiles] = useState([]); - - const handleChange = (newFiles: IImageInputFile[], updatedIndexes?: number[]) => { - setImageFiles(newFiles); - }; - - return ( -
-
-

Tipe Debitur

-
-
-
-
- -
- - setFormData((prev: any) => ({ ...prev, account_number: target.value })) - } - placeholder="Nomor Rekening" - /> -
-
-
-
-
- -
- - setFormData((prev: any) => ({ ...prev, amount: target.value })) - } - placeholder="Nominal Pinjaman" - /> -
-
-
-
-
- -
-
- - setFormData((prev: any) => ({ ...prev, period_amount: target.value })) - } - placeholder="Jangka Waktu" - /> -
-
- -
-
-
-
-
- ); -}; - -export { StepFour }; diff --git a/src/pages/pengajuan_kredit/list/steps/StepOne.tsx b/src/pages/pengajuan_kredit/list/steps/StepOne.tsx deleted file mode 100644 index 64fd643..0000000 --- a/src/pages/pengajuan_kredit/list/steps/StepOne.tsx +++ /dev/null @@ -1,252 +0,0 @@ -import { useEffect, useState } from 'react'; -import { Input } from '@/components/ui/input'; -import { DatePicker } from '../blocks'; -import { KeenIcon } from '@/components'; -import { ImageInput, IImageInputFile } from '@/components/image-input'; -import { apiConfig } from '@/config/api.config'; -import { useCallApi } from '@/hooks'; -import { toast } from 'sonner'; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue -} from '@/components/ui/select'; - -const API_URL = apiConfig.service_credit; - -const StepOne = ({ setFormData, formData }: any) => { - const [applicationDate, setApplicationDate] = useState(new Date()); - const [imageFiles, setImageFiles] = useState<{ [key: string]: IImageInputFile[] }>({}); - const [selectCompanyList, setSelectCompanyList] = useState([]); - const { PostData, GetData } = useCallApi(); - - const uploadFile = async (file: File, name: any) => { - console.log(file); - try { - const formData = new FormData(); - formData.append('file', file); - - const response = await PostData(`${API_URL}/application/file/upload`, formData); - console.log(response?.message.name); - if (response?.status) { - toast.success('Success upload document'); - let obj = []; - obj[name] = response.message.name; - setFormData((prevState: any) => ({ - ...prevState, - ...obj - })); - } - } catch (error) { - console.error('Error uploading file:', error); - } - }; - - const handleImageChange = (name: string) => (value: IImageInputFile[]) => { - setImageFiles((prev) => ({ - ...prev, - [name]: value - })); - - value.forEach((item) => { - if (item.file) { - uploadFile(item.file, name); - } - }); - }; - - const doGetListCompanyList = async (page: number, limit: number, sorting: any, filter: any) => { - sorting = sorting.length == 0 ? [{ id: 'created_at', desc: false }] : sorting; - filter = filter.length == 0 ? [] : filter[0].value; - - const response = await GetData(`${API_URL}/company/list`, { - limit: 1000, - page: 1, - with_deleted: false, - order_field: 'id', - order_direction: 'ASC', - filter: JSON.stringify({ status: 'Y' }) - }); - - return { data: response?.data.list, totalCount: response?.data.total_count }; - }; - - useEffect(() => { - const fetchCompanyList = async () => { - try { - const { data } = await doGetListCompanyList(1, 1000, [], []); - setSelectCompanyList(data); - } catch (error) { - console.error('Failed to fetch instansi', error); - } - }; - fetchCompanyList(); - }, []); - return ( -
-
-

Data Calon Debitur

-
-
-
-
-
- - - setFormData((prev: any) => ({ ...prev, name: target.value })) - } - placeholder="Nama Lengkap Debitur" - /> -
-
-
-
- - - setFormData((prev: any) => ({ ...prev, employee_id: target.value })) - } - placeholder="Employee ID" - /> -
-
-
-
-
-
- - - setFormData((prev: any) => ({ ...prev, phone: target.value })) - } - placeholder="Nomor Telpon" - /> -
-
-
-
- - - setFormData((prev: any) => ({ ...prev, application_date: target.value })) - } - /> -
-
-
-
-
-
- -
- -
- - {({ fileList, onImageUpload, onImageRemove, dragProps, isDragging }) => ( - -
- )) - ) : ( -
Click here to import file
- )} -
-
- - )} - -
- -
-
- - -
-
- - - ); -}; - -export { StepOne }; diff --git a/src/pages/pengajuan_kredit/list/steps/StepThree.tsx b/src/pages/pengajuan_kredit/list/steps/StepThree.tsx deleted file mode 100644 index 169423f..0000000 --- a/src/pages/pengajuan_kredit/list/steps/StepThree.tsx +++ /dev/null @@ -1,133 +0,0 @@ -import React, { useEffect, useState } from 'react'; -import { useCallApi } from '@/hooks'; -import { KeenIcon } from '@/components'; -import { ImageInput, IImageInputFile } from '@/components/image-input'; -import { apiConfig } from '@/config/api.config'; -import { toast } from 'sonner'; - -const API_URL = apiConfig.service_credit; - -const StepThree = ({ setFormData, formData }: any) => { - const [imageFiles, setImageFiles] = useState<{ [key: string]: IImageInputFile[] }>({}); - const [formList, setFormList] = useState([]); - const { PostData, GetData } = useCallApi(); - - const uploadFile = async (file: File, name: string, id: string) => { - // console.log(file); - try { - const formData = new FormData(); - formData.append('file', file); - - const response = await PostData(`${API_URL}/application/file/upload`, formData); - - if (response?.status) { - toast.success('Success upload document'); - // let obj = { [name]: response.message.name }; - let form = { - id: id, - name: name, - type: 'file', - value: response?.message.name - }; - console.log('form:', form); - setFormData((prevState: any) => ({ - ...prevState, - form: [...prevState.form, form] // Tambahkan form ke array form - })); - } - } catch (error) { - console.error('Error uploading file:', error); - } - }; - const handleImageChange = (name: string, id: string) => (value: IImageInputFile[]) => { - setImageFiles((prev) => ({ - ...prev, - [name]: value - })); - - value.forEach((item) => { - if (item.file) { - uploadFile(item.file, name, id); - } - }); - }; - - const doGetFormList = async (code: string) => { - const response = await GetData(`${API_URL}/application/form/list`, { - code: formData?.type - }); - return { data: response?.data }; - }; - - useEffect(() => { - const fetchFormList = async () => { - try { - const { data } = await doGetFormList(formData?.type); - setFormList(data); - } catch (error) { - console.error('Failed to fetch form type', error); - } - }; - fetchFormList(); - }, []); - - return ( -
-
-

Persyaratan Lain

-
-
-
- {formList.map((type, index) => ( -
-
- -

{type.label_red}

-
- - {({ fileList, onImageUpload, onImageRemove, dragProps, isDragging }) => ( - -
- )) - ) : ( -
Click here to import file
- )} -
-
- - )} - - - ))} - - - ); -}; - -export { StepThree }; diff --git a/src/pages/pengajuan_kredit/list/steps/StepTwo.tsx b/src/pages/pengajuan_kredit/list/steps/StepTwo.tsx deleted file mode 100644 index e70b940..0000000 --- a/src/pages/pengajuan_kredit/list/steps/StepTwo.tsx +++ /dev/null @@ -1,377 +0,0 @@ -import { useState } from 'react'; -import { KeenIcon } from '@/components'; -import { ImageInput, IImageInputFile } from '@/components/image-input'; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue -} from '@/components/ui/select'; -import { apiConfig } from '@/config/api.config'; -import { useCallApi } from '@/hooks'; -import { toast } from 'sonner'; - -const API_URL = apiConfig.service_credit; - -const StepTwo = ({ setFormData, formData }: any) => { - const [imageFiles, setImageFiles] = useState<{ [key: string]: IImageInputFile[] }>({}); - const { PostData } = useCallApi(); - - const uploadFile = async (file: File, name: string) => { - // console.log(file); - try { - const formData = new FormData(); - formData.append('file', file); - - const response = await PostData(`${API_URL}/application/file/upload`, formData); - if (response?.status) { - toast.success('Success upload document'); - let obj = { [name]: response.message.name }; - setFormData((prevState: any) => ({ - ...prevState, - ...obj - })); - } - } catch (error) { - console.error('Error uploading file:', error); - } - }; - - const handleImageChange = (name: string) => (value: IImageInputFile[]) => { - setImageFiles((prev) => ({ - ...prev, - [name]: value - })); - - value.forEach((item) => { - if (item.file) { - uploadFile(item.file, name); - } - }); - }; - - return ( -
-
-

Tipe Debitur

-
-
-
-
- -
- -
-
-
-
-
-
- -
- -
-
- - {({ fileList, onImageUpload, onImageRemove, dragProps, isDragging }) => ( - -
- )) - ) : ( -
Click here to import file
- )} -
-
- - )} - -
-
- - -
-
- - - {({ fileList, onImageUpload, onImageRemove, dragProps, isDragging }) => ( - -
- )) - ) : ( -
Click here to import file
- )} -
- - - )} - - - - - {formData.marriage_type === 'Certidão Casamento' && ( - <> -
-
-
- -
- - -
- - {({ fileList, onImageUpload, onImageRemove, dragProps, isDragging }) => ( - -
- )) - ) : ( -
Click here to import file
- )} -
- - - )} - - - -
- -
- - {({ fileList, onImageUpload, onImageRemove, dragProps, isDragging }) => ( - -
- )) - ) : ( -
Click here to import file
- )} -
- - - )} - - -
- - {({ fileList, onImageUpload, onImageRemove, dragProps, isDragging }) => ( - -
- )) - ) : ( -
Click here to import file
- )} - - - - )} - - - - - - )} - - ); -}; - -export { StepTwo }; diff --git a/src/pages/pengajuan_kredit/list/steps/index.ts b/src/pages/pengajuan_kredit/list/steps/index.ts deleted file mode 100644 index 9edcbdc..0000000 --- a/src/pages/pengajuan_kredit/list/steps/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './StepOne'; -export * from './StepTwo'; -export * from './StepThree'; -export * from './StepFour'; diff --git a/src/pages/pengajuan_kredit/summary/CreditSummaryPage.tsx b/src/pages/pengajuan_kredit/summary/CreditSummaryPage.tsx deleted file mode 100644 index 09615dc..0000000 --- a/src/pages/pengajuan_kredit/summary/CreditSummaryPage.tsx +++ /dev/null @@ -1,224 +0,0 @@ -import { Container, KeenIcon, ContentLoader, DefaultTooltip } from '@/components'; -import { useCallback, useState } from 'react'; -import { DateRangePicker, List, ListToolBar, DetailDialog } from './blocks'; - -import { CreditSummaryContextProvider, useCreditSummaryContext } from './hooks'; - -import { formatDate } from 'date-fns'; -import { DateRange } from 'react-day-picker'; -import { Button } from '@/components/ui/button'; -import { Toaster } from '@/components/ui/sonner'; -import { toAbsoluteUrl } from '@/utils'; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue -} from '@/components/ui/select'; -import { toast } from 'sonner'; - -type IntervalType = 'day' | 'week' | 'month'; -type CountType = 'sum' | 'count'; - -interface CreditSummaryExportProps { - date: DateRange | undefined; - interval: 'day' | 'week' | 'month'; - count: 'sum' | 'count'; - loadingButton: LoadingButton | boolean; - isLoading: boolean; -} - -type LoadingButton = 'filter' | 'reset' | 'export' | 'refresh' | null; - -const CreditSummaryPage = () => { - const [date, setDate] = useState({ - from: new Date(new Date().setDate(new Date().getDate() - 14)), - to: new Date() - }); - const [isLoading, setIsLoading] = useState(false); - const [loadingButton, setLoadingButton] = useState(null); - const [openDialog, setOpenDialog] = useState(false); - const [titleDialog, setTitleDialog] = useState(''); - const [propsDialog, setPropsDialog] = useState(); - const [interval, setInterval] = useState('day'); - const [count, setCount] = useState('sum'); - const handleDialogClick = useCallback((title: string, props: {}) => { - setOpenDialog((openDialog) => !openDialog); - setTitleDialog(title); - setPropsDialog(props); - }, []); - - const [filter, setFilter] = useState({ - from: new Date(new Date().setDate(new Date().getDate() - 14)), - to: new Date(), - interval: 'day' as IntervalType, - count: 'sum' as CountType - }); - - const handleFilter = useCallback( - (date: DateRange | undefined) => { - setFilter((prev) => ({ - ...prev, - from: date?.from ?? new Date(new Date().setDate(new Date().getDate() - 14)), - to: date?.to ?? new Date(), - interval: interval, - count: count - })); - }, - [interval, count] - ); - - const handleSelect = (value: IntervalType) => { - setInterval(value); - if (value === 'day') { - setDate({ - from: new Date(new Date().setDate(new Date().getDate() - 14)), - to: new Date() - }); - } - }; - const handleCount = (value: CountType) => { - setCount(value); - }; - - const resetFilter = useCallback(() => { - setFilter((prev) => ({ - ...prev, - interval: 'day', - count: 'sum', - from: new Date(new Date().setDate(new Date().getDate() - 14)), - to: new Date() - })); - setInterval('day'); - setCount('sum'); - setDate({ - from: new Date(new Date().setDate(new Date().getDate() - 14)), - to: new Date() - }); - }, []); - - return ( - - -
- -
-
- -
-
- -
-
- -
- - - - - - -
-
- -
- - } - openDetail={handleDialogClick} - /> -
- handleDialogClick('', {})} - /> -
-
- ); -}; - -export const BgSummaryExport = ({ - date, - interval, - count, - loadingButton, - isLoading -}: CreditSummaryExportProps) => { - const { doExportData } = useCreditSummaryContext(); - - const handleExport = useCallback( - async (date: DateRange | undefined) => { - try { - const startDate = date?.from ?? new Date(new Date().setDate(new Date().getDate() - 31)); - const endDate = date?.to ?? new Date(); - - await doExportData(startDate, endDate, interval, count); - toast.success('Success export summary pengajuan kredit.'); - } catch (error) { - toast.error('Failed export data. Please try again.'); - } - }, - [doExportData, interval] - ); - - return ( -
- - - -
- ); -}; - -export default CreditSummaryPage; diff --git a/src/pages/pengajuan_kredit/summary/blocks/DateRangePicker.tsx b/src/pages/pengajuan_kredit/summary/blocks/DateRangePicker.tsx deleted file mode 100644 index cc5b033..0000000 --- a/src/pages/pengajuan_kredit/summary/blocks/DateRangePicker.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import { useCallback, useState } from 'react'; -import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'; -import { Calendar } from '@/components/ui/calendar'; -import { DateRange } from 'react-day-picker'; -import { format } from 'date-fns'; -import { KeenIcon } from '@/components/keenicons'; -import { cn } from '@/lib/utils'; -import moment from 'moment'; -import { toast } from 'sonner'; - -interface DateRangePickerProps { - date: DateRange | undefined; - setDate: (date: DateRange | undefined) => void; - interval: 'day' | 'week' | 'month'; -} - -function getDateRangeLength(startDate: Date, endDate: Date) { - const start = moment(startDate); - const end = moment(endDate); - - return end.diff(start, 'days') + 1; -} - -const DateRangePicker = ({ date, setDate, interval }: DateRangePickerProps) => { - const handleSelectDate = useCallback( - (date: DateRange | undefined) => { - if (date && date.from && date.to) { - const dateRange = getDateRangeLength(date.from, date.to); - setDate(date); - } else { - setDate(date); - } - }, - [interval, setDate] - ); - return ( - - - - - - - - - ); -}; - -export { DateRangePicker }; diff --git a/src/pages/pengajuan_kredit/summary/blocks/DetailDialog.tsx b/src/pages/pengajuan_kredit/summary/blocks/DetailDialog.tsx deleted file mode 100644 index 2f1f7de..0000000 --- a/src/pages/pengajuan_kredit/summary/blocks/DetailDialog.tsx +++ /dev/null @@ -1,333 +0,0 @@ -import { useEffect, useRef, useState, useMemo } from 'react'; -import { fShortenNumber, fCurrency } from '@/utils/FormatNumber'; -import { formatDate } from 'date-fns'; -import { DataGrid, DataGridColumnHeader, DataGridProvider, KeenIcon } from '@/components'; -import { ColumnDef } from '@tanstack/react-table'; -import axios from 'axios'; -import { apiConfig } from '@/config/api.config'; -import moment from 'moment'; -const API_URL = apiConfig.service_bank; -import { - Dialog, - DialogBody, - DialogContent, - DialogDescription, - DialogHeader, - DialogTitle -} from '@/components/ui/dialog'; - -interface IModalProps { - open: boolean; - title: string; - desc: string; - props: { start_date: string; end_date: string; filter: { [key: string]: any } }; - onOpenChange: () => void; -} -const defaultSorting = [{ id: 'id', desc: false }]; - -const DetailDialog = ({ open, title, desc, props, onOpenChange }: IModalProps) => { - const navBar = useRef(null); - const parentRef = useRef(null); - - // console.log('open, title, desc, props, onOpenChange :', open, title, desc, props, onOpenChange); - - const fecthData = async (page: number, limit: number, sorting: any, filter: any) => { - sorting = sorting.length == 0 ? [{ id: 'id', desc: false }] : sorting; - filter = filter.length == 0 ? [] : filter[0].value; - const startDate = props.start_date; - const endDate = props.end_date; - - delete props.filter?.start_date; - delete props.filter?.end_date; - delete props.filter['ca.open_date']; - filter = { - ...props.filter, - open_date_from: startDate, - open_date_to: endDate - }; - const response = await axios.get(`${API_URL}/bank/dpk/list/`, { - params: { - filter: JSON.stringify(filter), - limit: limit, - page: page + 1, - with_deleted: false, - order_field: sorting[0].id, - order_direction: sorting[0].desc == false ? 'ASC' : 'DESC' - } - }); - return { data: response.data.data.list, totalCount: response.data.data.total_count }; - }; - - const columns = useMemo[]>( - () => [ - { - accessorFn: (row) => row.cif_number, - id: 'cif_number', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.name, - id: 'name', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.account_number, - id: 'account_number', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.branch.code, - id: 'branch.code', - header: ({ column }) => ( - - ), - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => moment(row.open_date).format('YYYY-MM-DD'), - id: 'open_date', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.product.code, - id: 'product.code', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.product.name, - id: 'product.name', - header: ({ column }) => ( - - ), - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => fCurrency(row.current_balance), - id: 'current_balance', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.country_code, - id: 'country_code', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.country_name, - id: 'country_name', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.exposed_person_flag, - id: 'exposed_person_flag', - header: ({ column }) => ( - - ), - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.income_tier.name, - id: 'incomde_tier.code', - header: ({ column }) => ( - - ), - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.cif_type, - id: 'cif_type', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.status, - id: 'status', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.gender, - id: 'gender', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => (row.birth_date ? moment(row.birth_date).format('YYYY-MM-DD') : ''), - id: 'birth_date', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.class_economi.name, - id: 'class.economi.id', - header: ({ column }) => ( - - ), - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.district.name, - id: 'class.district.id', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.munisipiu.name, - id: 'class.munisipiu.id', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.administrativu.name, - id: 'class.administrativu.id', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.suco.name, - id: 'class.suco.id', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - }, - { - accessorFn: (row) => row.aldeia.name, - id: 'class.aldeia.id', - header: ({ column }) => , - enableSorting: false, - enableHiding: false, - meta: { - headerClassName: 'w-[350px]' - } - } - ], - [] - ); - return ( - - - - - -
-
-

{title}

-
- {desc} -
-
- -
-
- -
- - fecthData(pageIndex, pageSize, sorting, columnFilters) - } - /> -
-
-
-
- ); -}; -export { DetailDialog }; diff --git a/src/pages/pengajuan_kredit/summary/blocks/List.tsx b/src/pages/pengajuan_kredit/summary/blocks/List.tsx deleted file mode 100644 index 7c270c4..0000000 --- a/src/pages/pengajuan_kredit/summary/blocks/List.tsx +++ /dev/null @@ -1,133 +0,0 @@ -/* eslint-disable prettier/prettier */ -import { DataGrid, DataGridColumnHeader } from '@/components'; -import { fCurrency, fPercent } from '@/utils/FormatNumber'; -import { ColumnDef } from '@tanstack/react-table'; -import { ReactNode, useMemo, useState } from 'react'; -import { format } from 'date-fns'; -interface BgSummaryListInterface { - start_date: string; - end_date: string; - toolbar: ReactNode; - interval: string; - count: string; - openDetail: (title: string, props: {}) => void; -} - -import { useFetchCreditSummaryData } from '../hooks'; -import moment from 'moment'; -import { snakeToCamelCase, snakeToTitleCase } from '@/utils'; - -const List = ({ - start_date, - end_date, - interval, - count, - toolbar, - openDetail -}: BgSummaryListInterface) => { - const { data, isLoading, error } = useFetchCreditSummaryData( - start_date, - end_date, - interval, - count - ); - const [columnVisibility, setColumnVisibility] = useState({ - _filter: false - }); - - const columns = useMemo[]>(() => { - if (!data || data.length === 0) return []; - const dateKeys = Object.keys(data[0]) - .filter((key) => key.match(/^\d{4}-\d{2}-\d{2}/)) - .map((key) => key.split('_')[0]) - .filter((value, index, self) => self.indexOf(value) === index); - const baseColumns = [ - { - accessorFn: (row: any) => row['label'], - id: 'label', - header: ({ column }: any) => ( - - ), - enableSorting: false, - enableHiding: false, - cell: ({ row }: any) => { - const _className = - row.original.type === 'type' - ? 'ms-0 font-semibold text-gray-700' - : row.original.type === 'type' - ? 'ms-2 text-gray-900' - : 'ms-4 text-gray-700'; - return

{row.original['label']}

; - }, - meta: { - headerClassName: 'w-auto' - } - } - ]; - // Create dynamic groups for multi-level headers - const dateColumns = dateKeys.map((date) => ({ - id: date, - header: (() => { - if (interval === 'month') { - return format(new Date(date), 'MMM yyyy'); - } else if (interval === 'week') { - const momentDate = moment(date); - const startOfMonth = momentDate.clone().startOf('month'); - const weekNumber = momentDate.isoWeek() - startOfMonth.isoWeek() + 1; - return `Week ${weekNumber}, \n ${momentDate.format('MMM yyyy')}`; - } else if (interval === 'day') { - return format(new Date(date), 'MMM dd, yyyy'); - } - })(), - columns: ['total'].map((metric) => ({ - accessorFn: (row: any) => row[`${date}_${metric}`], - id: `${date}_${metric}`, - header: snakeToTitleCase(metric), - enableSorting: false, - enableHiding: false, - cell: ({ row }: { row: { original: Record } }) => { - const __type = row.original.type; - const _className = - __type === 'type' - ? 'ms-0 font-semibold text-gray-900' - : __type === 'type' - ? 'ms-2 text-gray-900' - : 'ms-6 text-gray-700'; - - let value = row.original[`${date}_${metric}`] || '0'; - if (count === 'sum') { - return {fCurrency(value)}; - } else { - return {value}; - } - }, - meta: { - headerClassName: 'text-center text-gray-900', - cellClassName: 'text-end' - } - })), - meta: { - headerClassName: 'text-center' - } - })); - - return [...baseColumns, ...dateColumns]; - }, [data, openDetail, start_date, end_date]); - - return ( - - ); -}; - -export { List }; diff --git a/src/pages/pengajuan_kredit/summary/blocks/ListToolBar.tsx b/src/pages/pengajuan_kredit/summary/blocks/ListToolBar.tsx deleted file mode 100644 index 88287cc..0000000 --- a/src/pages/pengajuan_kredit/summary/blocks/ListToolBar.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { type ReactNode } from 'react'; -export interface DpkSummaryListToolBarInterface { - children?: ReactNode; -} -const ListToolBar = ({ children }: DpkSummaryListToolBarInterface) => { - return ( -
-
-
{children}
-
-
- ); -}; - -export { ListToolBar }; diff --git a/src/pages/pengajuan_kredit/summary/blocks/index.ts b/src/pages/pengajuan_kredit/summary/blocks/index.ts deleted file mode 100644 index 0b8d392..0000000 --- a/src/pages/pengajuan_kredit/summary/blocks/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export * from './DateRangePicker'; -export * from './List'; -export * from './ListToolBar'; -export * from './DetailDialog'; \ No newline at end of file diff --git a/src/pages/pengajuan_kredit/summary/hooks/CreditSummaryContext.tsx b/src/pages/pengajuan_kredit/summary/hooks/CreditSummaryContext.tsx deleted file mode 100644 index 8386d6c..0000000 --- a/src/pages/pengajuan_kredit/summary/hooks/CreditSummaryContext.tsx +++ /dev/null @@ -1,60 +0,0 @@ -import React, { createContext } from 'react'; -import { apiConfig } from '@/config/api.config'; -import { useCallApi } from '@/hooks'; -import { format } from 'date-fns'; -import { doSaveLogActivity } from '@/actions/GlobalActions'; -import { getAuth } from '@/auth'; - -interface ContextProps { - doExportData: (startDate: Date, endDate: Date, interval: string, count: string) => Promise; -} - -const initialProps: ContextProps = { - doExportData: async () => {} -}; - -const CreditSummaryContext = createContext(initialProps); - -const CreditSummaryContextProvider = ({ children }: { children: React.ReactNode }) => { - /* state */ - const API_URL = apiConfig.service_credit; - const { GetExportData } = useCallApi(); - - /* action */ - const doExportData = async (startDate: Date, endDate: Date, interval: string, count: string) => { - try { - let param = { - interval: interval, - aggregate: count, - start_date: format(startDate, 'yyyy-MM-dd'), - end_date: format(endDate, 'yyyy-MM-dd'), - token: await getAuth()?.access_token - }; - - let url = `${API_URL}/application/summary/export`; - GetExportData(url, param, 'bank_garansi_summary_export'); - - const user = localStorage.getItem('user'); - const parsedUser = user ? JSON.parse(user) : null; - - const createActivity = { - module: 'Summary Pengajuan Kredit', - description: `Export Summary Pengajuan Kredit => ${parsedUser ? parsedUser.name : 'Unknown User'}`, - action: 'E' - }; - - doSaveLogActivity(createActivity); - } catch (error) { - console.error('Export failed:', error); - throw error; - } - }; - - return ( - - {children} - - ); -}; - -export { CreditSummaryContextProvider, CreditSummaryContext }; diff --git a/src/pages/pengajuan_kredit/summary/hooks/index.ts b/src/pages/pengajuan_kredit/summary/hooks/index.ts deleted file mode 100644 index e1d26a9..0000000 --- a/src/pages/pengajuan_kredit/summary/hooks/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './CreditSummaryContext'; -export * from './useCreditSummaryContext'; -export * from './useFetchCreditSummaryData'; diff --git a/src/pages/pengajuan_kredit/summary/hooks/useCreditSummaryContext.tsx b/src/pages/pengajuan_kredit/summary/hooks/useCreditSummaryContext.tsx deleted file mode 100644 index 5ae5a4d..0000000 --- a/src/pages/pengajuan_kredit/summary/hooks/useCreditSummaryContext.tsx +++ /dev/null @@ -1,12 +0,0 @@ -import { useContext } from 'react'; -import { CreditSummaryContext } from './CreditSummaryContext'; - -const useCreditSummaryContext = () => { - const context = useContext(CreditSummaryContext); - - if (!context) throw new Error('useCreditSummaryContext must be used within AuthProvider'); - - return context; -}; - -export { useCreditSummaryContext }; diff --git a/src/pages/pengajuan_kredit/summary/hooks/useFetchCreditSummaryData.tsx b/src/pages/pengajuan_kredit/summary/hooks/useFetchCreditSummaryData.tsx deleted file mode 100644 index 00b07e5..0000000 --- a/src/pages/pengajuan_kredit/summary/hooks/useFetchCreditSummaryData.tsx +++ /dev/null @@ -1,56 +0,0 @@ -import { useState, useEffect } from 'react'; -import axios from 'axios'; -import { formatDate } from 'date-fns'; -import { DateRange } from 'react-day-picker'; -import { apiConfig } from '@/config/api.config'; -import moment from 'moment'; - -const API_URL = apiConfig.service_credit; - -interface useFetchCreditSummaryDataResult { - data: any; - isLoading: boolean; - error: any; -} - -const useFetchCreditSummaryData = ( - start_date: string, - end_date: string, - interval: string, - count: string -): useFetchCreditSummaryDataResult => { - const [data, setData] = useState(null); - const [isLoading, setIsLoading] = useState(false); - const [error, setError] = useState(null); - - useEffect(() => { - const fetchData = async () => { - const filterInterval = interval; - - try { - setIsLoading(true); - const response = await axios.get(`${API_URL}/application/summary`, { - params: { - interval: filterInterval, - start_date: start_date, - end_date: end_date, - aggregate: count - } - }); - setData(response.data.data); - } catch (err) { - setError(err); - } finally { - setIsLoading(false); - } - }; - - if (start_date && end_date) { - fetchData(); - } - }, [start_date, end_date, interval, count]); - - return { data, isLoading, error }; -}; - -export { useFetchCreditSummaryData }; diff --git a/src/pages/pengajuan_kredit/summary/index.ts b/src/pages/pengajuan_kredit/summary/index.ts deleted file mode 100644 index 3ba11e3..0000000 --- a/src/pages/pengajuan_kredit/summary/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './CreditSummaryPage'; diff --git a/src/routing/AppRoutingSetup.tsx b/src/routing/AppRoutingSetup.tsx index 2b5a385..3f114db 100644 --- a/src/routing/AppRoutingSetup.tsx +++ b/src/routing/AppRoutingSetup.tsx @@ -9,17 +9,9 @@ import { ErrorsRouting } from '@/errors'; import DashboardHomePage from '@/pages/dashboards/home/DashboardHomePage'; import ConfigUserPage from '@/pages/settings/user/user/ConfigUserPage'; -import CreditChartPage from '@/pages/pengajuan_kredit/chart/CreditChartPage'; -import CreditSummaryPage from '@/pages/pengajuan_kredit/summary/CreditSummaryPage'; -import CreditListPage from '@/pages/pengajuan_kredit/list/CreditListPage'; -import CreditDetailPage from '@/pages/pengajuan_kredit/list/CreditDetailPage'; -import CreditAddPage from '@/pages/pengajuan_kredit/list/CreditAddPage'; - import LogActivityPage from '@/pages/settings/user/log-activity/LogActivityPage'; import ManagePositionPage from '@/pages/settings/user/manage-position/ManagePositionPage'; -import InstansiPage from '@/pages/instansi/InstansiPage'; - const AppRoutingSetup = (): ReactElement => { return (