You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

page.tsx 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. "use client";
  2. import React from 'react';
  3. import PageTitle from '@/components/ui/PageTitle';
  4. import { Typography, Flex, Row, Col } from 'antd';
  5. import type { Transaction } from '@/types/payment';
  6. import { getAllTransaction } from '@/app/api/general/paymentService';
  7. import { useQuery } from '@tanstack/react-query';
  8. import PaymentCard from '@/components/ui/PaymentCard';
  9. import AltLayout from '@/components/layout/AltLayout';
  10. import LoadingScreen from '@/components/layout/LoadingScreen';
  11. const { Text, Title } = Typography;
  12. const now = new Date();
  13. const month = now.toLocaleString('default', { month: 'long' });
  14. const year = now.getFullYear().toString();
  15. const CreatePersona: React.FC = () => {
  16. // Fetch payment types using React Query
  17. const { data: transactionList, error, isLoading } = useQuery<Transaction[] | undefined>({
  18. queryKey: ['getAllTransaction'],
  19. queryFn: getAllTransaction
  20. });
  21. // Show loading state while fetching data
  22. if (isLoading) return <LoadingScreen/>
  23. return (
  24. <AltLayout header={<PageTitle backButton={true}>TRANSACTION HISTORY</PageTitle>}>
  25. <Row className='!bg-white'>
  26. <Col span={24} className='z-10'>
  27. <Row className='!shadow-lg'>
  28. <Col span={24} className='!px-5 !py-3'>
  29. <Text className='!font-bold !text-lg'>
  30. {`Wallet Balance: RM
  31. ${transactionList?.reduce((accumVal, transaction) => accumVal + transaction.amount, 0)}
  32. `}
  33. </Text>
  34. </Col>
  35. <Col span={24} className='!px-5 !py-1 !bg-gray-200'>
  36. <Text className='!font-bold !text-sm !text-gray-500'>{`${month} ${year}`}</Text>
  37. </Col>
  38. </Row>
  39. </Col>
  40. <Col span={24}>
  41. <Flex vertical>
  42. {transactionList?.map(({ name, created_at, amount }) => <PaymentCard name={name} created_at={created_at} amount={amount} />)}
  43. </Flex>
  44. </Col>
  45. </Row>
  46. </AltLayout>
  47. );
  48. };
  49. export default CreatePersona;