-
Notifications
You must be signed in to change notification settings - Fork 162
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
3 changed files
with
160 additions
and
89 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 |
---|---|---|
@@ -1,18 +1,118 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React from 'react'; | ||
import React, { useRef } from 'react'; | ||
|
||
import { Box } from '~components'; | ||
import { Box, Button, Checkbox, Form, FormField, SpaceBetween, Textarea } from '~components'; | ||
|
||
import Bluedialog from './dialog'; | ||
import FeedbackDialog from './dialog'; | ||
|
||
export default function BluedialogPage() { | ||
import styles from './styles.scss'; | ||
|
||
export default function GenAIFeedback() { | ||
const [showDialog, setShowDialog] = React.useState(true); | ||
const submitData = (data: any) => { | ||
console.log(data); // submit the form with these values to determine next action | ||
const [showFeedbackSubmission, setShowFeedbackSubmission] = React.useState(false); | ||
const [errorMessage, setErrorMessage] = React.useState<string | null>(); | ||
const [feedbackOptions, setFeedbackOptions] = React.useState({ | ||
harmful: false, | ||
incomplete: false, | ||
inaccurate: false, | ||
other: false, | ||
}); | ||
const [feedbackText, setFeedbackText] = React.useState(''); | ||
const checkboxRef = useRef<HTMLElement>(null); | ||
|
||
const selectOption = (option: string, checked: boolean) => { | ||
setFeedbackOptions({ ...feedbackOptions, [option]: checked }); | ||
setErrorMessage(null); | ||
}; | ||
|
||
const submitData = () => { | ||
// Validation | ||
const isFeedbackOptionSelected = Object.values(feedbackOptions).some(val => !!val); | ||
if (!isFeedbackOptionSelected) { | ||
setErrorMessage('At least one option must be selected.'); | ||
// Move focus to the required input | ||
if (checkboxRef.current) { | ||
checkboxRef.current.focus(); | ||
} | ||
return; | ||
} | ||
|
||
// Submission | ||
setShowDialog(false); | ||
setShowFeedbackSubmission(true); | ||
}; | ||
const skipDialog = () => { | ||
|
||
const dismissDialog = () => { | ||
setShowDialog(false); | ||
}; | ||
return <Box padding="xxl">{showDialog && <Bluedialog onSubmit={submitData} onSkip={skipDialog} />}</Box>; | ||
|
||
return ( | ||
<Box padding="xxl"> | ||
{showDialog && ( | ||
<FeedbackDialog | ||
onDismiss={dismissDialog} | ||
footer={ | ||
<div className={styles['footer-buttons']}> | ||
<Button onClick={submitData} ariaLabel="Submit form"> | ||
Submit | ||
</Button> | ||
</div> | ||
} | ||
> | ||
<Form> | ||
<SpaceBetween direction="vertical" size="l"> | ||
<FormField label="What did you dislike about the response?" errorText={errorMessage}> | ||
<SpaceBetween size="xxl" direction="horizontal"> | ||
<Checkbox | ||
ref={checkboxRef} | ||
checked={feedbackOptions.harmful} | ||
onChange={({ detail }) => selectOption('harmful', detail.checked)} | ||
> | ||
Harmful | ||
</Checkbox> | ||
<Checkbox | ||
checked={feedbackOptions.incomplete} | ||
onChange={({ detail }) => selectOption('incomplete', detail.checked)} | ||
> | ||
Incomplete | ||
</Checkbox> | ||
<Checkbox | ||
checked={feedbackOptions.inaccurate} | ||
onChange={({ detail }) => selectOption('inaccurate', detail.checked)} | ||
> | ||
Inaccurate | ||
</Checkbox> | ||
<Checkbox | ||
checked={feedbackOptions.other} | ||
onChange={({ detail }) => selectOption('other', detail.checked)} | ||
> | ||
Other | ||
</Checkbox> | ||
</SpaceBetween> | ||
</FormField> | ||
|
||
<FormField | ||
label={ | ||
<span> | ||
Tell us more - <i>optional</i> | ||
</span> | ||
} | ||
stretch={true} | ||
> | ||
<Textarea | ||
rows={1} | ||
onChange={({ detail }) => setFeedbackText(detail.value)} | ||
value={feedbackText} | ||
placeholder={'Additional feedback'} | ||
/> | ||
</FormField> | ||
</SpaceBetween> | ||
</Form> | ||
</FeedbackDialog> | ||
)} | ||
|
||
{showFeedbackSubmission && <Box color="text-body-secondary">Thank you for the additional feedback.</Box>} | ||
</Box> | ||
); | ||
} |
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