Skip to content

Commit 9dba013

Browse files
ruth-avelarjackbravo
authored andcommitted
Remove the code from Select and add defaultValues
1 parent 1f88227 commit 9dba013

File tree

4 files changed

+23
-25
lines changed

4 files changed

+23
-25
lines changed

app/core/components/FormFields/SelectField.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@ import InputLabel from "@mui/material/InputLabel";
33
import MenuItem from "@mui/material/MenuItem";
44
import type { SelectChangeEvent } from "@mui/material/Select";
55
import Select from "@mui/material/Select";
6-
import React, { useEffect } from "react";
6+
import React from "react";
77
import { useField, useControlField } from "remix-validated-form";
88

99
interface SelectFieldProps {
1010
name: string;
1111
label: string;
1212
options: string[];
13-
value?: string;
1413
onChange?: (
1514
event?: SelectChangeEvent<string>,
1615
child?: React.ReactNode
@@ -28,7 +27,6 @@ const SelectField: React.FC<SelectFieldProps> = ({
2827
options,
2928
style,
3029
onChange,
31-
value,
3230
}) => {
3331
const { error } = useField(name);
3432
const [selectedValue, setSelectedValue] = useControlField<string>(name);
@@ -37,12 +35,6 @@ const SelectField: React.FC<SelectFieldProps> = ({
3735
setSelectedValue(event.target.value);
3836
};
3937

40-
useEffect(() => {
41-
if (value !== undefined) {
42-
setSelectedValue(value);
43-
}
44-
},[value, setSelectedValue])
45-
4638
return (
4739
<div>
4840
<FormControl style={style} error={!!error}>
@@ -71,4 +63,4 @@ const SelectField: React.FC<SelectFieldProps> = ({
7163
);
7264
};
7365

74-
export default SelectField;
66+
export default SelectField;

app/core/layouts/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { useOptionalUser } from "~/utils";
99
interface IProps {
1010
title: string;
1111
existApplicant?: boolean;
12-
applicantId?: string;
12+
applicantId?: string | number;
1313
}
1414
export interface MenuItemArgs {
1515
text: string;

app/routes/applicants.$applicantId._index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export default function Applicant() {
199199

200200
return (
201201
<>
202-
<Header title="Applicants" />
202+
<Header title="Applicants" applicantId={applicantId} />
203203
<Container>
204204
<Paper sx={{ p: 2 }}>
205205
<Grid container spacing={2}>

app/routes/applicationForm.$applicantId._index.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,19 @@ export default function FormPage() {
196196
const [startDate, setStartDate] = useState(getCurrentDate());
197197
const [editMode, setEditMode] = useState(false)
198198

199-
const editForm = () => {
199+
const editForm = async() => {
200200
if (profile.email === applicantByEmail?.email) {
201201
setEditMode(true)
202202
}
203203
}
204204

205-
useEffect(() => {
206-
editForm()
205+
useEffect( () => {
206+
editForm()
207207
})
208-
208+
209209
return (
210210
<Container>
211-
<Header title="Applicants"/>
211+
<Header title="Applicants" applicantId={applicantByEmail?.id.toString()} />
212212
<Paper sx={{ p: 2 }}>
213213
<img src="/HeaderImage.png" alt="Wizeline" style={{ width: "100%" }} />
214214
<Typography component="div" variant="h2">
@@ -226,6 +226,12 @@ export default function FormPage() {
226226
validator={validator}
227227
action="./createapplicant"
228228
method="post"
229+
defaultValues={{
230+
//TODO: add the selects info to edit the form
231+
232+
gender: editMode ? applicantByEmail?.gender : ""
233+
234+
}}
229235
>
230236
<Grid container spacing={10}>
231237
<Grid item xs={6}>
@@ -243,7 +249,7 @@ export default function FormPage() {
243249
label="I identify as:"
244250
options={["Male", "Female", "Non-binary", "Prefer not to say"]}
245251
style={{ width: "100%", marginBottom: "20px" }}
246-
value={editMode ? applicantByEmail?.gender : ''}
252+
247253
/>
248254
<LabeledTextField
249255
label="Full Name"
@@ -275,7 +281,7 @@ export default function FormPage() {
275281
"Vietnam",
276282
]}
277283
style={{ width: "100%", marginBottom: "20px" }}
278-
value={editMode ? applicantByEmail?.country : ''}
284+
// value={editMode ? applicantByEmail?.country : ''}
279285
/>
280286
<LabeledTextField
281287
name="dayOfBirth"
@@ -391,7 +397,7 @@ export default function FormPage() {
391397
"Wife",
392398
]}
393399
style={{ width: "100%", marginBottom: "20px" }}
394-
value={editMode ? (applicantByEmail?.emergencyRelationship ?? '') : ''}
400+
// value={editMode ? (applicantByEmail?.emergencyRelationship ?? '') : ''}
395401
/>
396402
<LabeledTextField
397403
label="Emergency phone number"
@@ -425,7 +431,7 @@ export default function FormPage() {
425431
"Proficient (C1,C2)",
426432
]}
427433
style={{ width: "100%", marginBottom: "20px" }}
428-
value={editMode ? applicantByEmail?.englishLevel : ''}
434+
// value={editMode ? applicantByEmail?.englishLevel : ''}
429435
/>
430436
<LabeledTextField
431437
label="Degree and field you are studying"
@@ -486,7 +492,7 @@ export default function FormPage() {
486492
"Project Management",
487493
]}
488494
style={{ width: "100%", marginBottom: "20px" }}
489-
value={editMode ? (applicantByEmail?.interestedRoles ?? '') : ''}
495+
// value={editMode ? (applicantByEmail?.interestedRoles ?? '') : ''}
490496
/>
491497
<LabeledTextField
492498
label="Preferred tools, programs, frameworks, programming languages or libraries"
@@ -542,14 +548,14 @@ export default function FormPage() {
542548
"University talk",
543549
]}
544550
style={{ width: "100%", marginBottom: "20px" }}
545-
value={editMode ? applicantByEmail?.howDidYouHearAboutUs : ''}
551+
// value={editMode ? applicantByEmail?.howDidYouHearAboutUs : ''}
546552
/>
547553
<SelectField
548554
name="participatedAtWizeline"
549555
label="Have you participated in any program at Wizeline before?"
550556
options={["Yes", "No"]}
551557
style={{ width: "100%", marginBottom: "20px" }}
552-
value={editMode ? (applicantByEmail?.participatedAtWizeline ? 'true' : 'false') : ''}
558+
// value={editMode ? (applicantByEmail?.participatedAtWizeline ? 'true' : 'false') : ''}
553559
/>
554560
<SelectField
555561
name="wizelinePrograms"
@@ -562,7 +568,7 @@ export default function FormPage() {
562568
"Does not apply",
563569
]}
564570
style={{ width: "100%", marginBottom: "20px" }}
565-
value={editMode ? (applicantByEmail?.wizelinePrograms ?? '') : ''}
571+
// value={editMode ? (applicantByEmail?.wizelinePrograms ?? '') : ''}
566572
/>
567573
<LabeledTextField
568574
label="Any additional comments?"

0 commit comments

Comments
 (0)