Skip to content

Commit 397b8a6

Browse files
committed
SHARED:VKT(Frontend): Pass accepted filetypes as prop to FileUpload, use actual upload logic
1 parent fcba232 commit 397b8a6

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

frontend/packages/shared/src/components/FileUpload/FileUpload.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { ChangeEvent, FC } from 'react';
22
import './FileUpload.scss';
33

44
type FileUploadProps = {
5+
accept?: string;
56
onChange: (files: FileList) => void;
67
};
78

8-
export const FileUpload: FC<FileUploadProps> = ({ onChange }) => {
9+
export const FileUpload: FC<FileUploadProps> = ({ accept, onChange }) => {
910
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
1011
if (event.target.files) {
1112
onChange(event.target.files);
@@ -15,7 +16,7 @@ export const FileUpload: FC<FileUploadProps> = ({ onChange }) => {
1516
return (
1617
<div className="custom-fileupload">
1718
<div className="rows gapped">
18-
<input type="file" onChange={handleChange} />
19+
<input accept={accept} type="file" onChange={handleChange} />
1920
</div>
2021
</div>
2122
);

frontend/packages/vkt/src/components/publicEnrollment/steps/EducationDetails.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import {
77
import { FileUpload, H2, Text } from 'shared/components';
88

99
import { usePublicTranslation } from 'configs/i18n';
10+
import { useAppDispatch, useAppSelector } from 'configs/redux';
11+
import { PublicExamEvent } from 'interfaces/publicExamEvent';
12+
import { startFileUpload } from 'redux/reducers/publicFileUpload';
13+
import { publicEnrollmentSelector } from 'redux/selectors/publicEnrollment';
1014

1115
export const EducationDetails = ({
1216
handleChange,
@@ -17,11 +21,19 @@ export const EducationDetails = ({
1721
keyPrefix: 'vkt.component.publicEnrollment.steps.educationDetails',
1822
});
1923

24+
const { id } = useAppSelector(publicEnrollmentSelector)
25+
.examEvent as PublicExamEvent;
26+
const dispatch = useAppDispatch();
27+
2028
const handleRadioChange = () => {
2129
handleChange(true);
2230
};
2331

24-
const handleFileUpload = (_files: FileList) => {};
32+
const handleFileUpload = (files: FileList) => {
33+
if (files.length > 0) {
34+
dispatch(startFileUpload({ file: files[0], examEventId: id }));
35+
}
36+
};
2537

2638
return (
2739
<div className="margin-top-lg rows gapped">
@@ -61,7 +73,10 @@ export const EducationDetails = ({
6173
</RadioGroup>
6274
</FormControl>
6375
</fieldset>
64-
<FileUpload onChange={handleFileUpload} />
76+
<FileUpload
77+
accept="application/pdf,image/jpeg,image/png"
78+
onChange={handleFileUpload}
79+
/>
6580
</div>
6681
);
6782
};
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { RootState } from 'configs/redux';
2+
import { PublicEnrollmentState } from 'redux/reducers/publicEnrollment';
23

3-
export const publicEnrollmentSelector = (state: RootState) =>
4-
state.publicEnrollment;
4+
export const publicEnrollmentSelector = (
5+
state: RootState,
6+
): PublicEnrollmentState => state.publicEnrollment;

0 commit comments

Comments
 (0)