-
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.
Allow modifying grouped subsection (#1191)
* provide required fields in page request * Fix block_pivot_nbr * Fix reset when deselecting * Clear if changed from appears to not * Testing --------- Co-authored-by: Michael Peels <[email protected]>
- Loading branch information
Showing
28 changed files
with
382 additions
and
56 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
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
File renamed without changes.
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
106 changes: 106 additions & 0 deletions
106
...page-builder/page/management/edit/question/GroupQuestion/Update/UpdateGroupedQuestion.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,106 @@ | ||
import { Button } from '@trussworks/react-uswds'; | ||
import { useAlert } from 'alert'; | ||
import { ButtonBar } from 'apps/page-builder/components/ButtonBar/ButtonBar'; | ||
import { CloseableHeader } from 'apps/page-builder/components/CloseableHeader/CloseableHeader'; | ||
import { PagesSubSection } from 'apps/page-builder/generated'; | ||
import { GroupRequest, useGroupSubsection } from 'apps/page-builder/hooks/api/useGroupSubsection'; | ||
import { Spinner } from 'components/Spinner'; | ||
import { useEffect, useState } from 'react'; | ||
import { FormProvider, useForm } from 'react-hook-form'; | ||
import { RepeatingBlock } from '../RepeatingBlock'; | ||
import { SubsectionDetails } from '../SubsectionDetails'; | ||
import styles from './update-group-question.module.scss'; | ||
|
||
type Props = { | ||
page: number; | ||
subsection: PagesSubSection; | ||
onSuccess: () => void; | ||
onCancel: () => void; | ||
}; | ||
export const UpdateGroupedQuestion = ({ page, subsection, onSuccess, onCancel }: Props) => { | ||
const { showAlert } = useAlert(); | ||
const { isLoading, error, response, group } = useGroupSubsection(); | ||
const [valid, setValid] = useState(false); | ||
const form = useForm<GroupRequest>({ | ||
mode: 'onChange', | ||
defaultValues: { | ||
name: subsection.name, | ||
batches: subsection.questions.map((question) => ({ | ||
appearsInTable: question.appearsInBatch, | ||
width: question.batchWidth, | ||
label: question.batchLabel, | ||
id: question.id | ||
})), | ||
blockName: subsection.blockName, | ||
visible: subsection.visible, | ||
repeatingNbr: subsection.questions[0]?.dataMartRepeatNumber ?? 0 | ||
} | ||
}); | ||
|
||
useEffect(() => { | ||
form.reset({ | ||
name: subsection.name, | ||
batches: subsection.questions.map((question) => ({ | ||
appearsInTable: question.appearsInBatch, | ||
width: question.batchWidth, | ||
label: question.batchLabel, | ||
id: question.id | ||
})), | ||
blockName: subsection.blockName, | ||
visible: subsection.visible, | ||
repeatingNbr: subsection.questions[0]?.dataMartRepeatNumber ?? 0 | ||
}); | ||
}, [JSON.stringify(subsection)]); | ||
|
||
const handleCancel = () => { | ||
form.reset(); | ||
onCancel(); | ||
}; | ||
|
||
const handleSubmit = () => { | ||
group(page, subsection.id, { ...form.getValues() }); | ||
}; | ||
|
||
useEffect(() => { | ||
if (response) { | ||
showAlert({ | ||
type: 'success', | ||
header: 'Grouped', | ||
message: `You've successfully grouped ${form.getValues('blockName')} subsection` | ||
}); | ||
form.reset(); | ||
onSuccess(); | ||
} else if (error) { | ||
showAlert({ | ||
type: 'error', | ||
header: 'error', | ||
message: 'Failed to group subsection' | ||
}); | ||
} | ||
}, [error, response]); | ||
|
||
return ( | ||
<div className={styles.groupQuestion}> | ||
{isLoading && ( | ||
<div className={styles.loadingIndicator}> | ||
<Spinner /> | ||
</div> | ||
)} | ||
<CloseableHeader title="Edit subsection" onClose={handleCancel} /> | ||
<div className={styles.content}> | ||
<FormProvider {...form}> | ||
<SubsectionDetails /> | ||
<RepeatingBlock questions={subsection.questions} valid={valid} setValid={setValid} /> | ||
</FormProvider> | ||
</div> | ||
<ButtonBar> | ||
<Button onClick={handleCancel} type="button" outline> | ||
Cancel | ||
</Button> | ||
<Button onClick={handleSubmit} type="button" disabled={!valid || !form.formState.isValid}> | ||
Submit | ||
</Button> | ||
</ButtonBar> | ||
</div> | ||
); | ||
}; |
46 changes: 46 additions & 0 deletions
46
...lder/page/management/edit/question/GroupQuestion/Update/update-group-question.module.scss
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 @@ | ||
@use 'styles/colors'; | ||
|
||
.groupQuestion { | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
|
||
.loadingIndicator div { | ||
max-height: 80svh; | ||
} | ||
|
||
.content { | ||
height: 100%; | ||
overflow-y: auto; | ||
padding: 1.25rem; | ||
} | ||
|
||
.form { | ||
height: 100%; | ||
overflow-y: auto; | ||
|
||
width: 100%; | ||
min-width: 100%; | ||
max-width: unset; | ||
overflow-y: auto; | ||
height: calc(100% - 5.5rem); | ||
padding: 1.5rem; | ||
} | ||
.footer { | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-end; | ||
margin: 0 -1.5rem; | ||
padding: 0 1.5rem; | ||
gap: 0.5rem; | ||
position: absolute; | ||
bottom: 0; | ||
height: 5rem; | ||
width: 100%; | ||
background-color: colors.$base-white; | ||
border-top: 1px solid colors.$base-lighter; | ||
button { | ||
margin: 0; | ||
} | ||
} | ||
} |
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.