Skip to content

Commit

Permalink
Merge branch 'main' into vsr_individual
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminJohnson2204 authored Feb 25, 2024
2 parents af07992 + 3750b82 commit 5321b1d
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 59 deletions.
2 changes: 0 additions & 2 deletions backend/src/models/vsr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const vsrSchema = new Schema({
age: { type: Number, require: true },
maritalStatus: { type: String, required: true },
spouseName: { type: String },
numOfBoys: { type: Number, required: true },
numOfGirls: { type: Number, required: true },
agesOfBoys: { type: [Number] },
agesOfGirls: { type: [Number] },
ethnicity: { type: [String], require: true },
Expand Down
64 changes: 32 additions & 32 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"@emotion/styled": "^11.11.0",
"@material/textfield": "^14.0.0",
"@mui/material": "^5.15.5",
"@mui/material": "^5.15.6",
"@mui/styled-engine-sc": "^6.0.0-alpha.13",
"@testing-library/jest-dom": "^6.1.4",
"@testing-library/react": "^14.1.2",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/api/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async function fetchRequest(
headers: Record<string, string>,
): Promise<Response> {
const hasBody = body !== undefined;

const newHeaders = { ...headers };
if (hasBody) {
newHeaders["Content-Type"] = "application/json";
Expand Down Expand Up @@ -55,13 +56,12 @@ async function assertOk(response: Response): Promise<void> {
const text = await response.text();
if (text) {
message += ": " + text;
console.log(message);
}
} catch (e) {
// skip errors
}

// throw new Error(message);
throw new Error(message);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/app/vsr/page.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,17 @@
border-radius: 4px;
}

.sectionHeader {
gap: 4px;
font-size: 16px;
color: black;
font-family: "Open Sans";
font-style: normal;
font-weight: 400;
line-height: normal;
margin: 16px 0 -8px;
}

.longText {
flex: 1;
}
Expand Down
67 changes: 44 additions & 23 deletions frontend/src/app/vsr/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@ const VeteranServiceRequest: React.FC = () => {
age: data.age,
maritalStatus: data.marital_status,
spouseName: data.spouse,
agesOfBoys: data.ages_of_boys?.slice(0, data.num_boys) ?? [],
agesOfGirls: data.ages_of_girls?.slice(0, data.num_girls) ?? [],
agesOfBoys:
data.ages_of_boys
?.slice(0, data.num_boys)
.map((age) => (typeof age === "number" ? age : parseInt(age))) ?? [],
agesOfGirls:
data.ages_of_girls
?.slice(0, data.num_girls)
.map((age) => (typeof age === "number" ? age : parseInt(age))) ?? [],
ethnicity: selectedEthnicities.concat(otherEthnicity === "" ? [] : [otherEthnicity]),
employmentStatus: data.employment_status,
incomeLevel: data.income_level,
Expand Down Expand Up @@ -126,7 +132,7 @@ const VeteranServiceRequest: React.FC = () => {
pattern: {
// Only allow up to 2 digits
value: /^[0-9][0-9]?$/,
message: "This field must be a number no greater than 100",
message: "This field must be a number less than 100",
},
})}
required
Expand All @@ -136,7 +142,8 @@ const VeteranServiceRequest: React.FC = () => {
</div>

<div className={styles.numChildren}>
{Array.from({ length: numChildrenThisGender }, (_, index) => (
{/* Cap it at 99 children per gender to avoid freezing web browser */}
{Array.from({ length: Math.min(numChildrenThisGender, 99) }, (_, index) => (
<div key={index} className={styles.childInputWrapper}>
<TextField
label={`Age`}
Expand All @@ -148,6 +155,10 @@ const VeteranServiceRequest: React.FC = () => {
value: /^[0-9]+$/,
message: "This field must be a number",
},
max: {
value: 17,
message: "Only enter children under 18",
},
})}
error={!!errors[`ages_of_${gender}s`]?.[index]}
helperText={errors[`ages_of_${gender}s`]?.[index]?.message}
Expand Down Expand Up @@ -231,9 +242,17 @@ const VeteranServiceRequest: React.FC = () => {
<div className={styles.longText}>
<TextField
label="Age"
type="number"
variant="outlined"
placeholder="Enter your age"
{...register("age", { required: "Age is required" })}
{...register("age", {
required: "Age is required",
pattern: {
// Only allow up to 2 digits
value: /^[0-9]+$/,
message: "This field must be a number",
},
})}
required
error={!!errors.age}
helperText={errors.age?.message}
Expand All @@ -259,26 +278,28 @@ const VeteranServiceRequest: React.FC = () => {
/>
)}
/>
<div className={styles.formRow}>
<div className={styles.longText}>
<TextField
label="Spouse's Name"
variant="outlined"
placeholder="e.g. Jane Timberlake"
{...register("spouse", {
required:
["Married", "Widowed/Widower"].includes(watch().marital_status) &&
"Spouse's Name is required",
})}
required={["Married", "Widowed/Widower"].includes(watch().marital_status)}
error={!!errors.spouse}
helperText={errors.spouse?.message}
/>
{watch().marital_status === "Married" ? (
<div className={styles.formRow}>
<div className={styles.longText}>
<TextField
label="Spouse's Name"
variant="outlined"
placeholder="e.g. Jane Timberlake"
{...register("spouse", {
required: "Spouse's Name is required",
})}
required
error={!!errors.spouse}
helperText={errors.spouse?.message}
/>
</div>
{/* Add an empty div here with flex: 1 to take up the right half of the row */}
<div style={{ flex: 1 }} />
</div>
{/* Add an empty div here with flex: 1 to take up the right half of the row */}
<div style={{ flex: 1 }} />
</div>
) : null}

<p className={styles.sectionHeader}>Children (under 18)</p>

<div className={styles.formRow}>
{renderChildInput("boy")}
{renderChildInput("girl")}
Expand Down

0 comments on commit 5321b1d

Please sign in to comment.