Skip to content

Commit

Permalink
fix(protocol-designer): submit and don't show again fixes (#15230)
Browse files Browse the repository at this point in the history
  • Loading branch information
jerader authored May 22, 2024
1 parent f76fea1 commit 2ede48c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 9 additions & 4 deletions protocol-designer/src/components/FilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,14 @@ export const FilePage = (): JSX.Element => {
const saveFileMetadata = (nextFormValues: FileMetadataFields): void => {
dispatch(actions.saveFileMetadata(nextFormValues))
}

const [isManualDirty, setManualDirty] = React.useState<boolean>(false)
const {
handleSubmit,
watch,
control,
setValue,
formState: { isDirty },
} = useForm<FileMetadataFields>({ defaultValues: formValues })

// to ensure that values from watch are up to date if the defaultValues
// change
React.useEffect(() => {
Expand Down Expand Up @@ -155,6 +154,7 @@ export const FilePage = (): JSX.Element => {
name="protocolName"
value={protocolName}
onChange={field.onChange}
onClick={() => setManualDirty(true)}
/>
)}
/>
Expand All @@ -172,6 +172,7 @@ export const FilePage = (): JSX.Element => {
name="author"
value={author}
onChange={field.onChange}
onClick={() => setManualDirty(true)}
/>
)}
/>
Expand All @@ -190,6 +191,7 @@ export const FilePage = (): JSX.Element => {
name="description"
value={description}
onChange={field.onChange}
onClick={() => setManualDirty(true)}
/>
)}
/>
Expand All @@ -198,9 +200,12 @@ export const FilePage = (): JSX.Element => {
<OutlineButton
type="submit"
className={styles.update_button}
disabled={!isDirty}
disabled={!isDirty || !isManualDirty}
onClick={() => setManualDirty(false)}
>
{isDirty ? t('application:update') : t('application:updated')}
{isManualDirty
? t('application:update')
: t('application:updated')}
</OutlineButton>
</div>
</form>
Expand Down
10 changes: 6 additions & 4 deletions protocol-designer/src/components/Hints/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ const HINT_IS_ALERT: HintKey[] = ['add_liquids_and_labware']

export const Hints = (): JSX.Element | null => {
const { t } = useTranslation(['alert', 'nav', 'button'])
const [rememberDismissal, toggleRememberDismissal] = React.useState<boolean>(
const [rememberDismissal, setRememberDismissal] = React.useState<boolean>(
false
)

const toggleRememberDismissal = React.useCallback(() => {
setRememberDismissal(prevDismissal => !prevDismissal)
}, [])
const hintKey = useSelector(selectors.getHint)
const dispatch = useDispatch()
const removeHint = (hintKey: HintKey): void => {
Expand Down Expand Up @@ -159,9 +163,7 @@ export const Hints = (): JSX.Element | null => {
<DeprecatedCheckboxField
className={styles.dont_show_again}
label={t('hint.dont_show_again')}
onChange={() => {
toggleRememberDismissal(rememberDismissal)
}}
onChange={toggleRememberDismissal}
value={rememberDismissal}
/>
<OutlineButton
Expand Down

0 comments on commit 2ede48c

Please sign in to comment.