Skip to content

Commit

Permalink
fix bugs in global settings page (#761)
Browse files Browse the repository at this point in the history
* fix bugs in global settings page

* change values in restore button

* set default values in form
  • Loading branch information
cpprian authored Sep 2, 2024
1 parent 4feb19c commit c300343
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './styles.scss';
import { zodResolver } from '@hookform/resolvers/zod';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import parse from 'html-react-parser';
import { useEffect, useMemo } from 'react';
import { useMemo } from 'react';
import { SubmitHandler, useForm } from 'react-hook-form';
import { useBreakpoint } from 'use-breakpoint';
import { z } from 'zod';
Expand Down Expand Up @@ -117,16 +117,12 @@ export const BrandingSettings = () => {
};
}, [settings?.instance_name, settings?.main_logo_url, settings?.nav_logo_url]);

const { control, handleSubmit, reset } = useForm<Settings>({
const { control, handleSubmit, setValue } = useForm<Settings>({
defaultValues,
mode: 'all',
resolver: zodResolver(zodSchema),
});

useEffect(() => {
reset();
}, [reset, defaultValues]);

const onSubmit: SubmitHandler<FormFields> = (submitted) => {
mutate(mergeWithDefaults(submitted));
};
Expand Down Expand Up @@ -156,7 +152,12 @@ export const BrandingSettings = () => {
icon={<IconCheckmarkWhite />}
styleVariant={ButtonStyleVariant.PRIMARY}
loading={isLoading}
onClick={() => setDefaultBrandingMutation('1')}
onClick={() => {
setDefaultBrandingMutation('1');
setValue('instance_name', defaultSettings.instance_name);
setValue('main_logo_url', '');
setValue('nav_logo_url', '');
}}
/>
<Button
form="branding-form"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import './styles.scss';
import { zodResolver } from '@hookform/resolvers/zod';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { AxiosError } from 'axios';
import { useEffect, useMemo } from 'react';
import { useMemo } from 'react';
import { SubmitHandler, useForm } from 'react-hook-form';
import { useBreakpoint } from 'use-breakpoint';
import { z } from 'zod';
Expand Down Expand Up @@ -78,16 +78,12 @@ export const LicenseSettings = () => {
};
}, [settings?.license]);

const { control, handleSubmit, reset } = useForm<Settings>({
const { control, handleSubmit } = useForm<Settings>({
defaultValues,
mode: 'all',
resolver: zodResolver(zodSchema),
});

useEffect(() => {
reset();
}, [reset, defaultValues]);

const onSubmit: SubmitHandler<FormFields> = (submitted) => {
mutate(submitted);
};
Expand Down
2 changes: 1 addition & 1 deletion web/src/shared/hooks/useApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ const useApi = (props?: HookProps): ApiHook => {
const getAppInfo: ApiHook['getAppInfo'] = () => client.get('/info').then(unpackRequest);

const setDefaultBranding: ApiHook['settings']['setDefaultBranding'] = (id: string) =>
client.get(`/settings/${id}`).then(unpackRequest);
client.put(`/settings/${id}`).then(unpackRequest);

const downloadSupportData: ApiHook['support']['downloadSupportData'] = async () =>
client.get<unknown>(`/support/configuration`).then((res) => res.data);
Expand Down

0 comments on commit c300343

Please sign in to comment.