Skip to content

Commit

Permalink
allow users to select multiple templates
Browse files Browse the repository at this point in the history
  • Loading branch information
rm03 committed Oct 15, 2024
1 parent 2c0b4cd commit 4b30983
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 9 deletions.
27 changes: 21 additions & 6 deletions frontend/components/ClubPage/ClubApprovalDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const ClubApprovalDialog = ({ club }: Props): ReactElement | null => {
const [confirmModal, setConfirmModal] = useState<ConfirmParams | null>(null)
const [fairs, setFairs] = useState<ClubFair[]>([])
const [templates, setTemplates] = useState<Template[]>([])
const [selectedTemplates, setSelectedTemplates] = useState<Template[]>([])

const canApprove = apiCheckPermission('clubs.approve_club')
const seeFairStatus = apiCheckPermission('clubs.see_fair_status')
Expand All @@ -62,7 +63,11 @@ const ClubApprovalDialog = ({ club }: Props): ReactElement | null => {
.then((resp) => resp.json())
.then(setTemplates)
}
}, [])

setComment(
selectedTemplates.map((template) => template.content).join('\n\n'),
)
}, [selectedTemplates])

return (
<>
Expand Down Expand Up @@ -211,17 +216,27 @@ const ClubApprovalDialog = ({ club }: Props): ReactElement | null => {
<div className="field is-grouped mb-3">
<div className="control is-expanded">
<Select
isMulti
isClearable
placeholder="Select a template"
placeholder="Select templates"
options={templates.map((template) => ({
value: template.id,
label: template.title,
content: template.content,
author: template.author,
}))}
onChange={(selectedOption) => {
selectedOption
? setComment(selectedOption.content)
: setComment('')
onChange={(selectedOptions) => {
if (selectedOptions) {
const selected = selectedOptions.map((option) => ({
id: option.value,
title: option.label,
content: option.content,
author: option.author,
}))
setSelectedTemplates(selected)
} else {
setSelectedTemplates([])
}
}}
/>
</div>
Expand Down
33 changes: 30 additions & 3 deletions frontend/components/Settings/QueueTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@ const QueueTableModal = ({
templates,
}: QueueTableModalProps): ReactElement => {
const [comment, setComment] = useState<string>('')
const [selectedTemplates, setSelectedTemplates] = useState<Template[]>([])

useEffect(() => {
setComment(
selectedTemplates.map((template) => template.content).join('\n\n'),
)
}, [selectedTemplates])

return (
<Modal
show={show}
closeModal={() => {
setComment('')
setSelectedTemplates([])
closeModal()
}}
marginBottom={false}
Expand All @@ -49,15 +58,33 @@ const QueueTableModal = ({
{isApproving ? 'approve' : 'reject'} these requests.
</div>
<Select
isMulti
isClearable
placeholder="Select a template"
placeholder="Select templates"
value={selectedTemplates.map((template) => ({
value: template.id,
label: template.title,
content: template.content,
author: template.author,
}))}
options={templates.map((template) => ({
value: template.id,
label: template.title,
content: template.content,
author: template.author,
}))}
onChange={(selectedOption) => {
selectedOption ? setComment(selectedOption.content) : setComment('')
onChange={(selectedOptions) => {
if (selectedOptions) {
const selected = selectedOptions.map((option) => ({
id: option.value,
title: option.label,
content: option.content,
author: option.author,
}))
setSelectedTemplates(selected)
} else {
setSelectedTemplates([])
}
}}
/>
<textarea
Expand Down

0 comments on commit 4b30983

Please sign in to comment.