-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #221 from OxfordRSE/fix-dropdown-courses
New process of adding and ordering material sections in the edit eventgroup
- Loading branch information
Showing
7 changed files
with
353 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React, { useState } from "react" | ||
import Stack from "components/ui/Stack" | ||
import type { FieldValues } from "react-hook-form" | ||
import { Button } from "@mui/material" | ||
import SelectSectionField from "components/forms/SelectSectionField" | ||
import type { Option } from "components/forms/SelectSectionField" | ||
|
||
interface EventItemAdderProps<T extends FieldValues> { | ||
sectionsOptions: Option[] | ||
selectedOptions: Option[] | ||
setSelectedOptions: React.Dispatch<React.SetStateAction<Option[]>> | ||
handleAddClick: () => void | ||
inputValue?: string | ||
setInputValue: React.Dispatch<React.SetStateAction<string>> | ||
className?: string | ||
} | ||
|
||
function EventItemAdder({ | ||
sectionsOptions, | ||
selectedOptions, | ||
setSelectedOptions, | ||
handleAddClick, | ||
inputValue, | ||
setInputValue, | ||
className, | ||
}: EventItemAdderProps<FieldValues>) { | ||
return ( | ||
<Stack direction="row"> | ||
<SelectSectionField | ||
label="Section" | ||
name="" | ||
options={sectionsOptions} | ||
selectedOptions={selectedOptions} | ||
setSelectedOptions={setSelectedOptions} | ||
inputValue={inputValue} | ||
setInputValue={setInputValue} | ||
className={className} | ||
/> | ||
<Button onClick={handleAddClick} variant="contained" size="small" className="rounded"> | ||
Add Sections | ||
</Button> | ||
</Stack> | ||
) | ||
} | ||
|
||
export default EventItemAdder |
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,89 @@ | ||
import React from "react" | ||
import { useForm, Control, Controller, FieldPath, FieldValues } from "react-hook-form" | ||
import { Autocomplete, TextField, Checkbox } from "@mui/material" | ||
import CheckBoxOutlineBlankIcon from "@mui/icons-material/CheckBoxOutlineBlank" | ||
import CheckBoxIcon from "@mui/icons-material/CheckBox" | ||
import { Chip } from "@mui/material" | ||
|
||
const icon = <CheckBoxOutlineBlankIcon fontSize="small" /> | ||
const checkedIcon = <CheckBoxIcon fontSize="small" /> | ||
|
||
export type Option = { | ||
value: any | ||
label: string | ||
} | ||
|
||
type Props<T extends FieldValues> = { | ||
label?: string | ||
name: FieldPath<T> | ||
options: Option[] | ||
rules?: Object | ||
className?: React.ComponentProps<"div">["className"] | ||
selectedOptions: Option[] | ||
setSelectedOptions: React.Dispatch<React.SetStateAction<Option[]>> | ||
inputValue?: string | ||
setInputValue: React.Dispatch<React.SetStateAction<string>> | ||
} | ||
|
||
function SelectSectionField<T extends FieldValues>({ | ||
label, | ||
name, | ||
options, | ||
className, | ||
selectedOptions, | ||
setSelectedOptions, | ||
inputValue, | ||
setInputValue, | ||
}: Props<T>): React.ReactElement { | ||
const filterOptions = (options: Option[], { inputValue }: { inputValue: string }) => { | ||
return options.filter((option) => option.label.toLowerCase().includes(inputValue.toLowerCase())) | ||
} | ||
return ( | ||
<div className={className} id="select"> | ||
<Autocomplete | ||
multiple | ||
inputValue={inputValue} | ||
disableCloseOnSelect={true} | ||
onChange={(event, newValue) => setSelectedOptions(newValue)} | ||
value={selectedOptions} | ||
id={name} | ||
options={options} | ||
getOptionLabel={(option) => option.label} | ||
filterOptions={filterOptions} | ||
isOptionEqualToValue={(option, value) => option.value === value.value} | ||
sx={{ width: 1000 }} | ||
renderOption={(props, option, { selected }) => ( | ||
<li {...props}> | ||
<Checkbox icon={icon} checkedIcon={checkedIcon} style={{ marginRight: 8 }} checked={selected} /> | ||
{option.label} | ||
</li> | ||
)} | ||
renderTags={(value, getTagProps) => | ||
value.map((option, index) => ( | ||
<Chip | ||
label={option.label} | ||
{...getTagProps({ index })} | ||
className="dark:bg-teal-500 dark:text-white" | ||
key={`chip-${option.value}`} | ||
/> | ||
)) | ||
} | ||
renderInput={(params) => ( | ||
<TextField | ||
{...params} | ||
placeholder="Choose Sections" | ||
label={name} | ||
error={false} | ||
onChange={(e) => setInputValue(e.target.value)} | ||
variant="outlined" | ||
className="block w-full rounded-lg border disabled:cursor-not-allowed disabled:opacity-50 bg-gray-50 | ||
border-gray-300 text-gray-900 focus:border-cyan-500 focus:ring-cyan-500 dark:border-gray-600 | ||
dark:bg-gray-700 dark:text-white dark:placeholder-gray-400 dark:focus:border-cyan-500 dark:focus:ring-cyan-500" | ||
/> | ||
)} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export default SelectSectionField |
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
Oops, something went wrong.