feat(documents): add document table and queries#12
Conversation
| contentType: ReportContentType.File, | ||
| }; | ||
|
|
||
| const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB |
There was a problem hiding this comment.
lets make this common constant
|
|
||
| const handleFileChange = useCallback((file: File | undefined) => { | ||
| if (isDefined(file) && file.size > MAX_FILE_SIZE) { | ||
| alert.show('File must be 5MB or smaller', { variant: 'danger' }); |
There was a problem hiding this comment.
we need to show this in non field error instead of alert, i think FileInput have size props to handle this.
subinasr
left a comment
There was a problem hiding this comment.
From now onwards, please try to adhere to the branch naming conventions.
For reference: https://notes.tools.togglecorp.com/6MN_ghZfS02ucm__t6_WCQ#
| } from '@ifrc-go/ui'; | ||
| import { type EntriesAsList } from '@togglecorp/toggle-form'; | ||
|
|
||
| import type { DocumentFilterType } from '../index'; |
There was a problem hiding this comment.
| import type { DocumentFilterType } from '../index'; | |
| import type { DocumentFilterType } from '..'; |
| function isAllowedReportType(value: string | null | undefined): value is ReportTypeEnum { | ||
| return isDefined(value) && (allowedReportTypes as string[]).includes(value); | ||
| } | ||
|
|
There was a problem hiding this comment.
Way too many type casts. There might be a way to simpler write the same function.
| } = useForm(documentSchema, { value: initialValue }); | ||
|
|
||
| const [{ data, fetching: documentDetailFetch }] = useDocumentDetailQuery({ | ||
| variables: { id: isDefined(id) ? id : '' }, |
There was a problem hiding this comment.
Why not send undefined when there's no id?
There was a problem hiding this comment.
undefined causes a type error (id is generated as string), so ''
| const reportTypeOptions = useMemo(() => ( | ||
| (enumsData?.enums?.ReportType ?? []).filter( | ||
| (option) => allowedReportTypes.includes(option.key), | ||
| ) | ||
| ), [enumsData]); |
There was a problem hiding this comment.
I believe there's useGlobalEnums hook you can use instead of separately fetching the enums.
| useEffect(() => { | ||
| if (!documentDetailFetch && isDefined(documentData)) { | ||
| const { | ||
| ...otherValues | ||
| } = removeNull(documentData); | ||
|
|
||
| delete (otherValues as { file?: unknown }).file; | ||
| setValue({ | ||
| ...otherValues, | ||
| }); | ||
| } | ||
| }, [documentDetailFetch, documentData, setValue]); |
There was a problem hiding this comment.
Can you check this properly? This can be done without so much destructuring and mutation of the object.
| title="File Upload" | ||
| description="Upload the document file" | ||
| withAsteriskOnTitle | ||
|
|
| function persistTab(value: string | null | undefined): ReportTypeEnum { | ||
| if (value === ReportTypeEnum.Policy || value === ReportTypeEnum.Guideline) { | ||
| return value; | ||
| } | ||
| return ReportTypeEnum.Manual; | ||
| } | ||
|
|
There was a problem hiding this comment.
This function is unnecessary.
| const tableData: ReportsListItem[] = useMemo(() => ( | ||
| (data?.reports?.results ?? []).map((report, index) => ({ | ||
| ...report, | ||
| no: String((page - 1) * limit + index + 1), |
There was a problem hiding this comment.
You can keep this as a number unless you have a specific reason for the type cast.
|
|
||
| import type { AdminAreaLevel } from '#generated/types/graphql'; | ||
|
|
||
| export const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB |
There was a problem hiding this comment.
Let's use two common variables here. MAX_REPORT_FILE_SIZE and MAX_IMAGE_FILE_SIZE as the limits for the two are different.
| setSizeError(`File must be ${Math.round(maxSize / (1024 * 1024))}MB or smaller`); | ||
| onChange(undefined, inputName); |
There was a problem hiding this comment.
Is this necessary? What do you think @shreeyash07 ?
Changes
This PR doesn't introduce any
console.logmeant for debugging