Skip to content

Commit f2bfdd6

Browse files
committed
Make travel questions optional
- Made `travelling_from` and `departure_city` fields mandatory only if `needsFundsForTravel` is set to "true". - Updated UI to hide these fields by default and show them only when `needsFundsForTravel` is "true". - Modified API to handle these fields as optional.
1 parent 0f63619 commit f2bfdd6

File tree

2 files changed

+55
-48
lines changed

2 files changed

+55
-48
lines changed

backend/api/grants/mutations.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def validate(self, conference: Conference, user: User) -> GrantErrors:
7979
for field, max_length in max_length_fields.items():
8080
value = getattr(self, field, "")
8181

82-
if len(value) > max_length:
82+
if value and len(value) > max_length:
8383
print(field)
8484
errors.add_error(
8585
field,
@@ -120,9 +120,9 @@ class SendGrantInput(BaseGrantInput):
120120
need_accommodation: bool
121121
why: str
122122
notes: str
123-
travelling_from: str
123+
travelling_from: str | None = None
124124
nationality: str
125-
departure_city: str
125+
departure_city: str | None = None
126126

127127
participant_bio: str
128128
participant_website: str
@@ -159,9 +159,9 @@ class UpdateGrantInput(BaseGrantInput):
159159
need_accommodation: bool
160160
why: str
161161
notes: str
162-
travelling_from: str
162+
travelling_from: str | None = None
163163
nationality: str
164-
departure_city: str
164+
departure_city: str | None = None
165165

166166
participant_bio: str
167167
participant_website: str

frontend/src/components/grant-form/index.tsx

Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -565,49 +565,56 @@ export const GrantForm = ({
565565
</FormattedMessage>
566566
</Select>
567567
</InputWrapper>
568-
569-
<InputWrapper
570-
required={true}
571-
title={<FormattedMessage id="grants.form.fields.travellingFrom" />}
572-
description={
573-
<FormattedMessage id="grants.form.fields.travellingFrom.description" />
574-
}
575-
>
576-
<Select
577-
{...select("travellingFrom")}
578-
required={true}
579-
errors={getErrors("travellingFrom")}
580-
>
581-
<FormattedMessage id="input.selectCountryPlaceholder">
582-
{(msg) => (
583-
<option value="" disabled>
584-
{msg}
585-
</option>
586-
)}
587-
</FormattedMessage>
588-
{countries.map((c) => (
589-
<option key={c.value} value={c.value}>
590-
{c.label}
591-
</option>
592-
))}
593-
</Select>
594-
</InputWrapper>
595-
596-
<InputWrapper
597-
required={true}
598-
title={<FormattedMessage id="grants.form.fields.departureCity" />}
599-
description={
600-
<FormattedMessage id="grants.form.fields.departureCity.description" />
601-
}
602-
>
603-
<Input
604-
{...text("departureCity")}
605-
required={true}
606-
maxLength={100}
607-
placeholder={inputPlaceholderText}
608-
errors={getErrors("departureCity")}
609-
/>
610-
</InputWrapper>
568+
{formState.values.needsFundsForTravel === "true" && (
569+
<>
570+
<InputWrapper
571+
required={false}
572+
title={
573+
<FormattedMessage id="grants.form.fields.travellingFrom" />
574+
}
575+
description={
576+
<FormattedMessage id="grants.form.fields.travellingFrom.description" />
577+
}
578+
>
579+
<Select
580+
{...select("travellingFrom")}
581+
required={true}
582+
errors={getErrors("travellingFrom")}
583+
>
584+
<FormattedMessage id="input.selectCountryPlaceholder">
585+
{(msg) => (
586+
<option value="" disabled>
587+
{msg}
588+
</option>
589+
)}
590+
</FormattedMessage>
591+
{countries.map((c) => (
592+
<option key={c.value} value={c.value}>
593+
{c.label}
594+
</option>
595+
))}
596+
</Select>
597+
</InputWrapper>
598+
599+
<InputWrapper
600+
required={false}
601+
title={
602+
<FormattedMessage id="grants.form.fields.departureCity" />
603+
}
604+
description={
605+
<FormattedMessage id="grants.form.fields.departureCity.description" />
606+
}
607+
>
608+
<Input
609+
{...text("departureCity")}
610+
required={true}
611+
maxLength={100}
612+
placeholder={inputPlaceholderText}
613+
errors={getErrors("departureCity")}
614+
/>
615+
</InputWrapper>
616+
</>
617+
)}
611618
</CardPart>
612619
</MultiplePartsCard>
613620

0 commit comments

Comments
 (0)