39462-vm/frontend/src/pages/payment_batches/payment_batches-view.tsx
2026-04-04 02:49:01 +00:00

717 lines
16 KiB
TypeScript

import React, { ReactElement, useEffect } from 'react';
import Head from 'next/head'
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";
import dayjs from "dayjs";
import {useAppDispatch, useAppSelector} from "../../stores/hooks";
import {useRouter} from "next/router";
import { fetch } from '../../stores/payment_batches/payment_batchesSlice'
import {saveFile} from "../../helpers/fileSaver";
import dataFormatter from '../../helpers/dataFormatter';
import ImageField from "../../components/ImageField";
import LayoutAuthenticated from "../../layouts/Authenticated";
import {getPageTitle} from "../../config";
import SectionTitleLineWithButton from "../../components/SectionTitleLineWithButton";
import SectionMain from "../../components/SectionMain";
import CardBox from "../../components/CardBox";
import BaseButton from "../../components/BaseButton";
import BaseDivider from "../../components/BaseDivider";
import {mdiChartTimelineVariant} from "@mdi/js";
import {SwitchField} from "../../components/SwitchField";
import FormField from "../../components/FormField";
import {hasPermission} from "../../helpers/userPermissions";
const Payment_batchesView = () => {
const router = useRouter()
const dispatch = useAppDispatch()
const { payment_batches } = useAppSelector((state) => state.payment_batches)
const { currentUser } = useAppSelector((state) => state.auth);
const { id } = router.query;
function removeLastCharacter(str) {
console.log(str,`str`)
return str.slice(0, -1);
}
useEffect(() => {
dispatch(fetch({ id }));
}, [dispatch, id]);
return (
<>
<Head>
<title>{getPageTitle('View payment_batches')}</title>
</Head>
<SectionMain>
<SectionTitleLineWithButton icon={mdiChartTimelineVariant} title={removeLastCharacter('View payment_batches')} main>
<BaseButton
color='info'
label='Edit'
href={`/payment_batches/payment_batches-edit/?id=${id}`}
/>
</SectionTitleLineWithButton>
<CardBox>
{hasPermission(currentUser, 'READ_ORGANIZATIONS') &&
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>Organization</p>
<p>{payment_batches?.organization?.name ?? 'No data'}</p>
</div>
}
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>BatchNumber</p>
<p>{payment_batches?.batch_number}</p>
</div>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>Status</p>
<p>{payment_batches?.status ?? 'No data'}</p>
</div>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>Currency</p>
<p>{payment_batches?.currency ?? 'No data'}</p>
</div>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>TotalAmount</p>
<p>{payment_batches?.total_amount || 'No data'}</p>
</div>
<FormField label='ScheduledAt'>
{payment_batches.scheduled_at ? <DatePicker
dateFormat="yyyy-MM-dd hh:mm"
showTimeSelect
selected={payment_batches.scheduled_at ?
new Date(
dayjs(payment_batches.scheduled_at).format('YYYY-MM-DD hh:mm'),
) : null
}
disabled
/> : <p>No ScheduledAt</p>}
</FormField>
<FormField label='ProcessedAt'>
{payment_batches.processed_at ? <DatePicker
dateFormat="yyyy-MM-dd hh:mm"
showTimeSelect
selected={payment_batches.processed_at ?
new Date(
dayjs(payment_batches.processed_at).format('YYYY-MM-DD hh:mm'),
) : null
}
disabled
/> : <p>No ProcessedAt</p>}
</FormField>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>PreparedBy</p>
<p>{payment_batches?.prepared_by_user?.firstName ?? 'No data'}</p>
</div>
<>
<p className={'block font-bold mb-2'}>Payments PaymentBatch</p>
<CardBox
className='mb-6 border border-gray-300 rounded overflow-hidden'
hasTable
>
<div className='overflow-x-auto'>
<table>
<thead>
<tr>
<th>PaymentReference</th>
<th>PaymentDate</th>
<th>Amount</th>
<th>Currency</th>
<th>Status</th>
<th>FailureReason</th>
</tr>
</thead>
<tbody>
{payment_batches.payments_batch && Array.isArray(payment_batches.payments_batch) &&
payment_batches.payments_batch.map((item: any) => (
<tr key={item.id} onClick={() => router.push(`/payments/payments-view/?id=${item.id}`)}>
<td data-label="payment_reference">
{ item.payment_reference }
</td>
<td data-label="payment_date">
{ dataFormatter.dateTimeFormatter(item.payment_date) }
</td>
<td data-label="amount">
{ item.amount }
</td>
<td data-label="currency">
{ item.currency }
</td>
<td data-label="status">
{ item.status }
</td>
<td data-label="failure_reason">
{ item.failure_reason }
</td>
</tr>
))}
</tbody>
</table>
</div>
{!payment_batches?.payments_batch?.length && <div className={'text-center py-4'}>No data</div>}
</CardBox>
</>
<BaseDivider />
<BaseButton
color='info'
label='Back'
onClick={() => router.push('/payment_batches/payment_batches-list')}
/>
</CardBox>
</SectionMain>
</>
);
};
Payment_batchesView.getLayout = function getLayout(page: ReactElement) {
return (
<LayoutAuthenticated
permission={'READ_PAYMENT_BATCHES'}
>
{page}
</LayoutAuthenticated>
)
}
export default Payment_batchesView;