Skip to content

Commit

Permalink
Feature/app 88 make the forms for guidance reports in admin service (#…
Browse files Browse the repository at this point in the history
…148)

Co-authored-by: Osneil Drakes <[email protected]>
  • Loading branch information
odrakes-cpr and Osneil Drakes authored Jan 14, 2025
1 parent 541880b commit a03c874
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/components/forms/metadata-handlers/familyForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
IGcfProjectsFamilyFormPost,
ICifProjectsMetadata,
ICifProjectsFamilyFormPost,
IReportsMetadata,
IReportsFamilyFormPost,
} from '../../../interfaces/Family'
import { IChakraSelect } from '@/interfaces'

Expand Down Expand Up @@ -71,6 +73,12 @@ interface IFamilyFormGefProjects extends IFamilyFormMcfProjects {
focal_area?: IChakraSelect[]
}

interface IFamilyFormReports extends IFamilyFormBase {
author?: string
author_type?: IChakraSelect
external_id?: string
}

type TFamilyFormMcfProjects =
| IFamilyFormAfProjects
| IFamilyFormGcfProjects
Expand Down Expand Up @@ -237,6 +245,23 @@ export const corpusMetadataHandlers: Record<
metadata,
}) as IGefProjectsFamilyFormPost,
},
Reports: {
extractMetadata: (formData: TFamilyFormSubmit) => {
const reportsData = formData as IFamilyFormReports
return {
author: reportsData.author ? [reportsData.author] : [],
author_type: reportsData.author_type
? [reportsData.author_type?.value]
: [],
external_id: reportsData.external_id ? [reportsData.external_id] : [],
} as IReportsMetadata
},
createSubmissionData: (baseData, metadata) =>
({
...baseData,
metadata,
}) as IReportsFamilyFormPost,
},
// Add other corpus types here with their specific metadata extraction logic
}

Expand Down
15 changes: 15 additions & 0 deletions src/interfaces/Family.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ export interface IGcfProjectsMetadata extends IMcfProjectsBaseMetadata {
theme: string[]
}

export interface IReportsMetadata extends IMetadata {
author: string[]
author_type: string[]
external_id: string[]
}

type TMcfProjectsMetadata =
| IAfProjectsMetadata
| IGefProjectsMetadata
Expand Down Expand Up @@ -103,6 +109,10 @@ interface IGcfProjectsFamily extends IFamilyBase {
metadata: IGcfProjectsMetadata
}

interface IReportsFamily extends IFamilyBase {
metadata: IReportsMetadata
}

type TMcfFamily =
| IAfProjectsFamily
| IGefProjectsFamily
Expand All @@ -113,6 +123,7 @@ export type TFamily =
| IInternationalAgreementsFamily
| ILawsAndPoliciesFamily
| TMcfFamily
| IReportsFamily

// DTO for Create and Write.
export interface IFamilyFormPostBase {
Expand Down Expand Up @@ -149,6 +160,10 @@ export interface IGcfProjectsFamilyFormPost extends IFamilyFormPostBase {
metadata: IGcfProjectsMetadata
}

export interface IReportsFamilyFormPost extends IFamilyFormPostBase {
metadata: IReportsMetadata
}

type TMcfFamilyFormPost =
| IAfProjectsFamilyFormPost
| IGefProjectsFamilyFormPost
Expand Down
8 changes: 8 additions & 0 deletions src/interfaces/Metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,12 @@ export const CORPUS_METADATA_CONFIG: CorpusMetadataConfig = {
renderFields: {},
validationFields: [],
},
Reports: {
renderFields: {
author: { type: FieldType.TEXT },
author_type: { type: FieldType.SINGLE_SELECT },
external_id: { type: FieldType.TEXT },
},
validationFields: ['author', 'author_type', 'external_id'],
},
}

0 comments on commit a03c874

Please sign in to comment.