Skip to content

Commit

Permalink
chore(config): do not submit and reset untouched form
Browse files Browse the repository at this point in the history
  • Loading branch information
kunish committed Oct 2, 2023
1 parent d7e18eb commit ba8bfcb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/components/LogoText.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const LogoText = () => {
return (
<a
className="bg-gradient-to-b from-primary to-secondary bg-clip-text text-2xl font-bold text-transparent transition-all duration-500 hover:text-primary"
className="bg-gradient-to-b from-primary to-secondary bg-clip-text p-2 text-2xl font-bold text-transparent transition-all duration-500 hover:text-primary"
href="https://github.com/daeuniverse/daed"
target="_blank"
rel="noreferrer"
Expand Down
9 changes: 6 additions & 3 deletions src/pages/ConfigPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const ConfigPage = () => {
resolver: zodResolver(configFormSchema),
defaultValues: configFormDefault
})
const untouched = Object.values(form.formState.dirtyFields).every((dirty) => !dirty)
const defaultConfigIdQuery = useGetJSONStorageRequest(['defaultConfigID'] as const)
const generalQuery = useGeneralQuery()
const configsQuery = useConfigsQuery()
Expand Down Expand Up @@ -97,6 +98,8 @@ export const ConfigPage = () => {
]
}, [generalQuery.data?.general.interfaces, t])

console.log(form.formState.dirtyFields)

return (
<div className="space-y-6">
<p>Configs</p>
Expand Down Expand Up @@ -187,7 +190,7 @@ export const ConfigPage = () => {
</DialogHeader>

<div className="py-2">
<Accordion type="multiple">
<Accordion type="multiple" defaultValue={['software-options']}>
<AccordionItem value="software-options">
<AccordionTrigger>{t('primitives.softwareOptions')}</AccordionTrigger>

Expand Down Expand Up @@ -641,11 +644,11 @@ export const ConfigPage = () => {
</div>

<DialogFooter>
<Button type="reset" variant="secondary" onClick={() => form.reset()}>
<Button type="reset" variant="secondary" disabled={untouched} onClick={() => form.reset()}>
{t('actions.reset')}
</Button>

<Button type="submit" loading={form.formState.isSubmitting}>
<Button type="submit" disabled={untouched} loading={form.formState.isSubmitting}>
{t('actions.submit')}
</Button>
</DialogFooter>
Expand Down

0 comments on commit ba8bfcb

Please sign in to comment.