-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
45 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from "react"; | ||
import {useState} from "react"; | ||
import SelectField from "../shared/fields/SelectField"; | ||
import {Fade} from "@mui/material"; | ||
import FieldGroup from "./FieldGroup"; | ||
|
||
export function CapacityField({fields, handleChange, capacityFieldId}) { | ||
const capacityFieldKey = `characteristic_${capacityFieldId}`; | ||
const [isCapacityLimited, setIsCapacityLimited] = useState(typeof fields[capacityFieldKey] !== 'undefined' | ||
? 'Yes' : 'No'); | ||
|
||
const handleChangeCapacity = e => { | ||
const value = e.target.value; | ||
setIsCapacityLimited(value); | ||
|
||
// if the new isCapacityLimited value is No, unset the inner field | ||
if (value === 'No') { | ||
handleChange(capacityFieldKey)(null); | ||
} | ||
} | ||
|
||
return <> | ||
<SelectField key={capacityFieldKey} label="Is Capacity Limited?" required value={isCapacityLimited} | ||
options={['Yes', 'No']} onChange={e => handleChangeCapacity(e)}/> | ||
{isCapacityLimited === "Yes" | ||
? <Fade in={isCapacityLimited === "Yes"}> | ||
<div> | ||
<FieldGroup component={'NumberField'} key={capacityFieldKey} | ||
label={'Capacity'} required inputProps={{min: 0}} | ||
value={fields[capacityFieldKey]} onChange={handleChange(capacityFieldKey)}/> | ||
</div> | ||
</Fade> | ||
: null | ||
} | ||
</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters