-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from vadymstebakov/main
New updates
- Loading branch information
Showing
35 changed files
with
1,467 additions
and
705 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ | |
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite + React + TS</title> | ||
<link rel="preconnect" href="https://fonts.googleapis.com" /> | ||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin /> | ||
<link href="https://fonts.googleapis.com/css2?family=Syne:[email protected]&display=swap" rel="stylesheet" /> | ||
</head> | ||
|
||
<body> | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import axios from 'axios'; | ||
import { getAccessToken } from '@/utils/auth/tokens'; | ||
|
||
export const http = axios.create({ | ||
baseURL: import.meta.env.VITE_API_URL, | ||
adapter: 'fetch', | ||
}); | ||
|
||
export const httpPrivate = axios.create({ | ||
baseURL: import.meta.env.VITE_API_URL, | ||
adapter: 'fetch', | ||
}); | ||
|
||
httpPrivate.interceptors.request.use( | ||
(config) => { | ||
const token = getAccessToken(); | ||
|
||
if (token) { | ||
config.headers.Authorization = `Bearer ${token}`; | ||
config.withCredentials = true; | ||
} | ||
|
||
return config; | ||
}, | ||
(error) => { | ||
return Promise.reject(error); | ||
} | ||
); |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { AxiosRequestConfig } from 'axios'; | ||
import { httpPrivate } from '@/api/@axios'; | ||
|
||
export type RefreshTokenData = { | ||
refreshToken: string; | ||
}; | ||
|
||
export type RefreshTokenResponseData = { | ||
accessToken: string; | ||
refreshToken: string; | ||
}; | ||
|
||
export const refreshToken = async (data: RefreshTokenData, config?: AxiosRequestConfig) => { | ||
const response = await httpPrivate.post<RefreshTokenResponseData>('/api/refresh-token', data, config); | ||
|
||
return response.data; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { AxiosRequestConfig } from 'axios'; | ||
import { httpPrivate } from '@/api/@axios'; | ||
|
||
export const getUsers = async (config?: AxiosRequestConfig) => { | ||
const response = await httpPrivate.get<string[]>('/api/users', config); | ||
|
||
return response.data; | ||
}; | ||
|
||
export const createUser = async (data: string, config?: AxiosRequestConfig) => { | ||
const response = await httpPrivate.post<string>('/api/users', data, config); | ||
|
||
return response.data; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
import type { DataTag, MutationFunction, QueryKey } from '@tanstack/react-query'; | ||
|
||
type Updater<TQueryFnData, TVariables> = ( | ||
_oldData: TQueryFnData | undefined, | ||
_variables: TVariables | ||
) => TQueryFnData | undefined; | ||
|
||
type OptimisticProps< | ||
TData = unknown, | ||
TVariables = unknown, | ||
TQueryKey extends QueryKey = QueryKey, | ||
TQueryFnData = unknown, | ||
> = { | ||
mutationFn: MutationFunction<TData, TVariables>; | ||
queryKey: TQueryKey; | ||
updater: Updater<TQueryFnData, TVariables>; | ||
invalidate: () => Promise<void>; | ||
}; | ||
|
||
export const useOptimisticMutation = < | ||
TData = unknown, | ||
TVariables = unknown, | ||
TQueryFnData = unknown, | ||
TQueryKey extends QueryKey = QueryKey, | ||
TInferredQueryFnData = TQueryKey extends DataTag<unknown, infer TaggedValue> ? TaggedValue : TQueryFnData, | ||
>({ | ||
mutationFn, | ||
queryKey, | ||
updater, | ||
invalidate, | ||
}: OptimisticProps<TData, TVariables, TQueryKey, TInferredQueryFnData>) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn, | ||
async onMutate(variables) { | ||
await queryClient.cancelQueries({ | ||
queryKey, | ||
}); | ||
|
||
const snapshot = queryClient.getQueryData(queryKey); | ||
|
||
queryClient.setQueryData<TInferredQueryFnData>(queryKey, (old) => { | ||
return updater(old, variables); | ||
}); | ||
|
||
return () => { | ||
queryClient.setQueryData(queryKey, snapshot); | ||
}; | ||
}, | ||
onError(_error, _variables, rollback) { | ||
rollback?.(); | ||
}, | ||
onSettled() { | ||
return invalidate(); | ||
}, | ||
}); | ||
}; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
|
||
export const useSetRootCustomProperty = (name: string, value?: string) => { | ||
React.useEffect(() => { | ||
if (value) { | ||
document.documentElement.style.setProperty(name, value); | ||
} else { | ||
document.documentElement.style.removeProperty(name); | ||
} | ||
}, [name, value]); | ||
}; |
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 was deleted.
Oops, something went wrong.
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
File renamed without changes.
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 +1 @@ | ||
export const CURRENT_YEAR = new Date().getFullYear(); | ||
export const EXAMPLE = 'Example'; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const useExampleHook = () => {}; |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { z } from 'zod'; | ||
|
||
export type ExampleSchema = z.infer<typeof exampleSchema>; | ||
|
||
export const exampleSchema = z.object({ | ||
name: z.string(), | ||
type: z.string(), | ||
}); |
File renamed without changes.
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type HomeExampleProps = { | ||
id?: number; | ||
name?: string; | ||
}; |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export const exampleUtil = () => {}; |
Oops, something went wrong.