From 07a4739ccf9fa5f3c078a327beb8ccf67d68e682 Mon Sep 17 00:00:00 2001 From: Georgi Parlakov Date: Sat, 24 Aug 2024 12:57:04 +0300 Subject: [PATCH] feat: admin campaign applications - show actual applications in the list --- src/common/hooks/campaign-applications.ts | 13 ++++ .../CampaignApplicationsGrid.tsx | 71 +++---------------- src/gql/campaign-applications.ts | 37 ++++++++++ .../admin/campaign-applications/index.tsx | 7 +- src/service/apiEndpoints.ts | 3 + 5 files changed, 68 insertions(+), 63 deletions(-) create mode 100644 src/common/hooks/campaign-applications.ts create mode 100644 src/gql/campaign-applications.ts diff --git a/src/common/hooks/campaign-applications.ts b/src/common/hooks/campaign-applications.ts new file mode 100644 index 000000000..e2f565701 --- /dev/null +++ b/src/common/hooks/campaign-applications.ts @@ -0,0 +1,13 @@ +import { useQuery } from '@tanstack/react-query' +import { CampaignApplication } from 'gql/campaign-applications' +import { useSession } from 'next-auth/react' +import { endpoints } from 'service/apiEndpoints' +import { authQueryFnFactory } from 'service/restRequests' + +export function useCampaignApplicationsAdminList() { + const { data: session } = useSession() + return useQuery( + [endpoints.campaignApplications.listAllAdmin.url], + authQueryFnFactory(session?.accessToken), + ) +} diff --git a/src/components/admin/campaign-applications/CampaignApplicationsGrid.tsx b/src/components/admin/campaign-applications/CampaignApplicationsGrid.tsx index a4e1e3473..64962a6fb 100644 --- a/src/components/admin/campaign-applications/CampaignApplicationsGrid.tsx +++ b/src/components/admin/campaign-applications/CampaignApplicationsGrid.tsx @@ -4,9 +4,13 @@ import { DataGrid, GridColDef, GridRenderCellParams } from '@mui/x-data-grid' import { routes } from 'common/routes' import theme from 'common/theme' import Link from 'next/link' +import { useCampaignApplicationsAdminList } from 'common/hooks/campaign-applications' +import { CampaignApplication } from 'gql/campaign-applications' export default function CampaignApplicationsGrid() { - const { t, i18n } = useTranslation() + const { t } = useTranslation() + + const { data = [] } = useCampaignApplicationsAdminList() const commonProps: Partial = { align: 'left', @@ -14,35 +18,35 @@ export default function CampaignApplicationsGrid() { headerAlign: 'left', } - const columns: GridColDef[] = [ + const columns: GridColDef[] = [ { - field: 'status', + field: 'state', headerName: t('campaigns:status'), ...commonProps, align: 'left', width: 220, }, { - field: 'title', + field: 'campaignName', headerName: t('campaigns:title'), ...commonProps, align: 'left', width: 250, renderCell: (cellValues: GridRenderCellParams) => ( - {cellValues.row.title} + {cellValues.row.campaignName} ), }, { - field: 'essence', + field: 'goal', headerName: t('campaigns:essence'), ...commonProps, align: 'left', width: 250, }, { - field: 'organizer', + field: 'organizerName', headerName: t('campaigns:organizer'), ...commonProps, align: 'left', @@ -71,59 +75,6 @@ export default function CampaignApplicationsGrid() { }, ] - const data = [ - { - updatedAt: 'date', - createdAt: '2024-5-5', - beneficiary: 'beneficiary', - organizer: 'organizer', - essence: 'essence', - title: 'title', - id: '1', - status: 'нова', - }, - { - updatedAt: 'yesterday', - createdAt: '10 days ago', - beneficiary: 'beneficiary', - organizer: 'organizer', - essence: 'essence', - title: 'title', - id: '2', - status: 'очаква документи', - }, - { - updatedAt: '', - createdAt: '', - beneficiary: 'beneficiary', - organizer: 'organizer', - essence: 'essence', - title: 'title', - id: '3', - status: 'очаква решение на комисия', - }, - - { - updatedAt: '', - createdAt: '', - beneficiary: 'beneficiary', - organizer: 'organizer', - essence: 'essence', - title: 'title', - id: '4', - status: 'одобрена', - }, - { - updatedAt: '', - createdAt: '', - beneficiary: 'beneficiary', - organizer: 'organizer', - essence: 'essence', - title: 'title', - id: '4', - status: 'отказана', - }, - ] return ( endpoints.campaignApplications.listAllAdmin.url, ) export default CampaignApplications diff --git a/src/service/apiEndpoints.ts b/src/service/apiEndpoints.ts index 629235b41..20d74dfdf 100644 --- a/src/service/apiEndpoints.ts +++ b/src/service/apiEndpoints.ts @@ -424,4 +424,7 @@ export const endpoints = { } }, }, + campaignApplications: { + listAllAdmin: { url: '/campaign-application/list', method: 'GET' }, + }, }