Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: admin campaign applications #1900

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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' },
},
}
Loading