-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creating-multiples-is-some-fun (#136)
* creating-multiples-is-some-fun * fix update team resolver
- Loading branch information
1 parent
1734781
commit 891766a
Showing
28 changed files
with
576 additions
and
102 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
11 changes: 0 additions & 11 deletions
11
...t/src/features/clues/components/CreateCluesDialog/MultipleClues/AddAnotherClueBlutton.tsx
This file was deleted.
Oops, something went wrong.
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
90 changes: 90 additions & 0 deletions
90
client/src/features/teams/components/CreateTeamsDialog/MultiTeamsFields.tsx
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,90 @@ | ||
import Box from "@mui/material/Box"; | ||
import IconButton from "@mui/material/IconButton"; | ||
import TextField from "@mui/material/TextField"; | ||
import DeleteOutlineIcon from "@mui/icons-material/DeleteOutline"; | ||
import { useController } from "react-hook-form"; | ||
import InputLabel from "@mui/material/InputLabel"; | ||
import { FieldWrapper } from "@lib/components/Form/FieldWrapper"; | ||
|
||
type MultiTeamFieldsProps = { | ||
index: number; | ||
remove: () => void; | ||
}; | ||
|
||
export const MultiTeamsFields = ({ index, remove }: MultiTeamFieldsProps) => { | ||
const { field: membersField, fieldState: membersFieldState } = useController({ | ||
name: `teams[${index}].members`, | ||
defaultValue: "", | ||
}); | ||
|
||
const { field: deviceField, fieldState: deviceFieldState } = useController({ | ||
name: `teams[${index}].device_number`, | ||
defaultValue: "", | ||
}); | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
display: "flex", | ||
flexDirection: "row", | ||
margin: "5px", | ||
alignItems: "center", | ||
justifyContent: "space-between", | ||
}} | ||
> | ||
<FieldWrapper sx={{ width: "100%" }}> | ||
<InputLabel required> | ||
Team members <i>(separated by a comma)</i> | ||
</InputLabel> | ||
<TextField | ||
slotProps={{ | ||
htmlInput: { | ||
"data-testid": `create-team-members-${index}`, | ||
}, | ||
}} | ||
multiline | ||
inputRef={membersField.ref} | ||
name={membersField.name} | ||
value={membersField.value} | ||
onBlur={membersField.onBlur} | ||
onChange={membersField.onChange} | ||
placeholder={`ie. 'Johnny, Sarah, Adam, Brittney'`} | ||
error={!!membersFieldState.error} | ||
helperText={ | ||
membersFieldState.error ? membersFieldState.error.message : null | ||
} | ||
color={membersFieldState.error ? "error" : "primary"} | ||
fullWidth | ||
variant="outlined" | ||
/> | ||
<InputLabel required>Cell phone number</InputLabel> | ||
<TextField | ||
slotProps={{ | ||
htmlInput: { | ||
"data-testid": `create-team-device-number-${index}`, | ||
}, | ||
}} | ||
inputRef={deviceField.ref} | ||
name={deviceField.name} | ||
value={deviceField.value} | ||
onBlur={deviceField.onBlur} | ||
onChange={deviceField.onChange} | ||
placeholder={`ie. +1-234-555-5678 or 2105551234`} | ||
error={!!deviceFieldState.error} | ||
helperText={ | ||
deviceFieldState.error ? deviceFieldState.error.message : null | ||
} | ||
color={deviceFieldState.error ? "error" : "primary"} | ||
fullWidth | ||
variant="outlined" | ||
/> | ||
</FieldWrapper> | ||
<IconButton | ||
onClick={remove} | ||
sx={{ height: "max-content", marginLeft: "4px" }} | ||
> | ||
<DeleteOutlineIcon /> | ||
</IconButton> | ||
</Box> | ||
); | ||
}; |
46 changes: 45 additions & 1 deletion
46
client/src/features/teams/components/CreateTeamsDialog/MultipleTeamsDialogContent.tsx
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 |
---|---|---|
@@ -1,3 +1,47 @@ | ||
import { useCallback, useEffect } from "react"; | ||
import { useFieldArray, useFormContext } from "react-hook-form"; | ||
import { FieldWrapper } from "@lib/components/Form/FieldWrapper"; | ||
import { useScrollShadow } from "@lib/hooks/useScrollShadow"; | ||
import Box from "@mui/material/Box"; | ||
import Button from "@mui/material/Button"; | ||
import { MultiTeamsFields } from "./MultiTeamsFields"; | ||
|
||
export const MultipleTeamsDialogContent = () => { | ||
return <div>MultipleTeamsDialogContent</div>; | ||
const { ref } = useScrollShadow(); | ||
const { | ||
setFocus, | ||
formState: { isSubmitting, isValid }, | ||
} = useFormContext(); | ||
|
||
const { fields, append, remove } = useFieldArray({ | ||
name: "teams", | ||
}); | ||
|
||
const addAnother = useCallback(() => { | ||
append({ members: "", device_number: "" }); | ||
setFocus(`teams[${fields.length + 1}]`, { shouldSelect: true }); | ||
}, [append, fields.length, setFocus]); | ||
|
||
useEffect(() => { | ||
if (fields.length === 0) { | ||
addAnother(); | ||
} | ||
}, [addAnother, fields]); | ||
|
||
return ( | ||
<FieldWrapper> | ||
<Box ref={ref} sx={{ maxHeight: "320px", overflowY: "auto" }}> | ||
{fields.map(({ id }, index) => ( | ||
<MultiTeamsFields | ||
key={id} | ||
index={index} | ||
remove={() => remove(index)} | ||
/> | ||
))} | ||
</Box> | ||
<Button disabled={!isValid || isSubmitting} onClick={addAnother}> | ||
Add another team | ||
</Button> | ||
</FieldWrapper> | ||
); | ||
}; |
Oops, something went wrong.