Skip to content

Commit

Permalink
feat: admin campaign applications
Browse files Browse the repository at this point in the history
- show actual applications in the list
  • Loading branch information
gparlakov-vmware committed Aug 24, 2024
1 parent 5471218 commit 07a4739
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 63 deletions.
13 changes: 13 additions & 0 deletions src/common/hooks/campaign-applications.ts
Original file line number Diff line number Diff line change
@@ -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<CampaignApplication[]>(
[endpoints.campaignApplications.listAllAdmin.url],
authQueryFnFactory<CampaignApplication[]>(session?.accessToken),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,49 @@ 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<GridColDef> = {
align: 'left',
width: 100,
headerAlign: 'left',
}

const columns: GridColDef[] = [
const columns: GridColDef<CampaignApplication>[] = [
{
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) => (
<Link href={routes.admin.campaignApplications.edit(cellValues.id.toString())}>
{cellValues.row.title}
{cellValues.row.campaignName}
</Link>
),
},
{
field: 'essence',
field: 'goal',
headerName: t('campaigns:essence'),
...commonProps,
align: 'left',
width: 250,
},
{
field: 'organizer',
field: 'organizerName',
headerName: t('campaigns:organizer'),
...commonProps,
align: 'left',
Expand Down Expand Up @@ -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 (
<DataGrid
style={{
Expand Down
37 changes: 37 additions & 0 deletions src/gql/campaign-applications.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { CampaignTypeCategory } from 'components/common/campaign-types/categories'

export type CampaignApplicationState =
| 'review'
| 'requestInfo'
| 'forCommitteeReview'
| 'approved'
| 'denied'
| 'abandoned'

export interface CampaignApplication {
id: string
createdAt: Date
updatedAt: Date | null
organizerId: string | null
organizerName: string
organizerEmail: string | null
organizerPhone: string | null
beneficiary: string
organizerBeneficiaryRel: string
campaignName: string
goal: string
history: string | null
amount: string
description: string | null
documents?: object[]
campaignGuarantee: string | null
otherFinanceSources: string | null
otherNotes: string | null
state: CampaignApplicationState
category: CampaignTypeCategory | null
ticketURL: string | null
archived: boolean | null
}


export type Keys = keyof CampaignApplication;
7 changes: 4 additions & 3 deletions src/pages/admin/campaign-applications/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import CampaignApplications from 'components/admin/campaign-applications/CampaignApplications'
import { securedPropsWithTranslation } from 'middleware/auth/securedProps'
import { securedAdminProps } from 'middleware/auth/securedProps'
import { GetServerSideProps } from 'next'
import { endpoints } from 'service/apiEndpoints'

export const getServerSideProps: GetServerSideProps = securedPropsWithTranslation(
export const getServerSideProps: GetServerSideProps = securedAdminProps(
['common', 'auth', 'validation', 'campaigns', 'campaign-application'],
'',
() => endpoints.campaignApplications.listAllAdmin.url,
)

export default CampaignApplications
3 changes: 3 additions & 0 deletions src/service/apiEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,7 @@ export const endpoints = {
}
},
},
campaignApplications: {
listAllAdmin: <Endpoint>{ url: '/campaign-application/list', method: 'GET' },
},
}

0 comments on commit 07a4739

Please sign in to comment.