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 };