Refactor query message toast
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { Box, Container, Flex, Heading, Text } from '@radix-ui/themes';
|
||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { Slide, toast, ToastContainer } from 'react-toastify';
|
||||
import { toast } from 'react-toastify/unstyled';
|
||||
import * as v from 'valibot';
|
||||
import { useResponseErrorHandler } from '../hooks/ResponseHelper';
|
||||
import { useApi } from '../providers/ApiProvider';
|
||||
import { formHook } from '../providers/FormProvider';
|
||||
import { TooltipContentContainer } from '../components/info';
|
||||
import { SearchParamKeys } from '../lib/constants';
|
||||
import { useQueryMessage } from '../hooks/useQueryMessage';
|
||||
import { QueryMessageCode, QueryMessageType } from '../lib/QueryMessages';
|
||||
|
||||
const initFormSchema = v.object({
|
||||
username: v.pipe(v.string(), v.trim(), v.minLength(1, 'Username is required')),
|
||||
@@ -19,12 +21,13 @@ export default function InitRoute() {
|
||||
const navigate = useNavigate();
|
||||
const { tanstackApiClient } = useApi();
|
||||
const { defaultResponseErrorHandler } = useResponseErrorHandler();
|
||||
const { toSearchParamQueryMessage } = useQueryMessage();
|
||||
|
||||
const { mutateAsync: initAdmin, isPending } = useMutation({
|
||||
...tanstackApiClient.mutation('post', '/api/auth/init_admin').mutationOptions,
|
||||
onSuccess: async () => {
|
||||
const searchParams = new URLSearchParams();
|
||||
searchParams.set(SearchParamKeys.Message, 'Initialization successful. Please log in.');
|
||||
searchParams.set(SearchParamKeys.Message, toSearchParamQueryMessage(QueryMessageCode.InitializationSuccessful, QueryMessageType.Success));
|
||||
navigate(`/login?${searchParams.toString()}`);
|
||||
},
|
||||
onError: (error) => {
|
||||
@@ -40,7 +43,7 @@ export default function InitRoute() {
|
||||
try {
|
||||
const data = await healthInfoQuery.queryFn!(...args);
|
||||
if (data.is_initialized) {
|
||||
navigate('/');
|
||||
navigate('/login', { replace: true });
|
||||
return data;
|
||||
}
|
||||
return data;
|
||||
@@ -153,18 +156,6 @@ export default function InitRoute() {
|
||||
</Box>
|
||||
</Container>
|
||||
</Flex>
|
||||
|
||||
<ToastContainer
|
||||
position="top-center"
|
||||
autoClose={false}
|
||||
newestOnTop={false}
|
||||
closeOnClick
|
||||
rtl={false}
|
||||
pauseOnFocusLoss
|
||||
draggable={false}
|
||||
theme="colored"
|
||||
transition={Slide}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user