From 468de704655bf8664df9a0b6f8e70683e55e7032 Mon Sep 17 00:00:00 2001 From: Ulle9 Date: Wed, 26 Jul 2023 10:59:55 +0300 Subject: [PATCH] onSucccess->onSuccess --- .../frontend/src/context/AuthContext.tsx | 8 ++++---- .../frontend/src/context/RSFormContext.tsx | 16 ++++++++-------- .../frontend/src/context/UsersContext.tsx | 4 ++-- .../frontend/src/hooks/useCheckExpression.ts | 2 +- rsconcept/frontend/src/hooks/useNewRSForm.ts | 2 +- .../frontend/src/hooks/useRSFormDetails.ts | 2 +- rsconcept/frontend/src/hooks/useRSForms.ts | 2 +- .../frontend/src/hooks/useUserProfile.ts | 3 ++- .../src/pages/RSFormsPage/RSFormsTable.tsx | 2 +- .../src/pages/UserProfilePage/UserProfile.tsx | 19 ++++++++++--------- .../src/pages/UserProfilePage/index.tsx | 2 +- rsconcept/frontend/src/utils/backendAPI.ts | 12 ++++++------ 12 files changed, 38 insertions(+), 36 deletions(-) diff --git a/rsconcept/frontend/src/context/AuthContext.tsx b/rsconcept/frontend/src/context/AuthContext.tsx index 52072836..411787fc 100644 --- a/rsconcept/frontend/src/context/AuthContext.tsx +++ b/rsconcept/frontend/src/context/AuthContext.tsx @@ -39,7 +39,7 @@ export const AuthState = ({ children }: AuthStateProps) => { async () => { await getAuth({ onError: () => { setUser(undefined); }, - onSucccess: response => { + onSuccess: response => { if (response.data.id) { setUser(response.data); } else { @@ -57,7 +57,7 @@ export const AuthState = ({ children }: AuthStateProps) => { showError: true, setLoading, onError: error => { setError(error); }, - onSucccess: + onSuccess: (response) => { loadCurrentUser() .then(() => { if (callback) callback(response); }) @@ -70,7 +70,7 @@ export const AuthState = ({ children }: AuthStateProps) => { setError(undefined); postLogout({ showError: true, - onSucccess: + onSuccess: (response) => { loadCurrentUser() .then(() => { if (callback) callback(response); }) @@ -86,7 +86,7 @@ export const AuthState = ({ children }: AuthStateProps) => { showError: true, setLoading, onError: error => { setError(error); }, - onSucccess: + onSuccess: (response) => { loadCurrentUser() .then(() => { if (callback) callback(response); }) diff --git a/rsconcept/frontend/src/context/RSFormContext.tsx b/rsconcept/frontend/src/context/RSFormContext.tsx index 2e28ac74..16e889a1 100644 --- a/rsconcept/frontend/src/context/RSFormContext.tsx +++ b/rsconcept/frontend/src/context/RSFormContext.tsx @@ -101,7 +101,7 @@ export const RSFormState = ({ schemaID, children }: RSFormStateProps) => { showError: true, setLoading: setProcessing, onError: error => { setError(error) }, - onSucccess: (response) => { + onSuccess: (response) => { reload(setProcessing) .then(() => { if (callback != null) callback(response); }) .catch(console.error); @@ -116,7 +116,7 @@ export const RSFormState = ({ schemaID, children }: RSFormStateProps) => { showError: true, setLoading: setProcessing, onError: error => { setError(error) }, - onSucccess: callback + onSuccess: callback }).catch(console.error); }, [schemaID, setError]) @@ -130,7 +130,7 @@ export const RSFormState = ({ schemaID, children }: RSFormStateProps) => { showError: true, setLoading: setProcessing, onError: error => { setError(error) }, - onSucccess: (response) => { + onSuccess: (response) => { schema.owner = user.id; schema.time_update = response.data.time_update; setSchema(schema); @@ -146,7 +146,7 @@ export const RSFormState = ({ schemaID, children }: RSFormStateProps) => { showError: true, setLoading: setProcessing, onError: error => { setError(error) }, - onSucccess: callback + onSuccess: callback }).catch(console.error); }, [schemaID, setError]) @@ -158,7 +158,7 @@ export const RSFormState = ({ schemaID, children }: RSFormStateProps) => { showError: true, setLoading: setProcessing, onError: error => { setError(error) }, - onSucccess: (response) => { + onSuccess: (response) => { reload(setProcessing) .then(() => { if (callback != null) callback(response); }) .catch(console.error); @@ -174,7 +174,7 @@ export const RSFormState = ({ schemaID, children }: RSFormStateProps) => { showError: true, setLoading: setProcessing, onError: error => { setError(error) }, - onSucccess: (response) => { + onSuccess: (response) => { setSchema(response.data.schema); if (callback != null) callback(response); } @@ -189,7 +189,7 @@ export const RSFormState = ({ schemaID, children }: RSFormStateProps) => { showError: true, setLoading: setProcessing, onError: error => { setError(error) }, - onSucccess: (response) => { + onSuccess: (response) => { setSchema(response.data) if (callback != null) callback(response) } @@ -204,7 +204,7 @@ export const RSFormState = ({ schemaID, children }: RSFormStateProps) => { showError: true, setLoading: setProcessing, onError: error => { setError(error) }, - onSucccess: (response) => { + onSuccess: (response) => { setSchema(response.data); if (callback != null) callback(response); } diff --git a/rsconcept/frontend/src/context/UsersContext.tsx b/rsconcept/frontend/src/context/UsersContext.tsx index fe7498a2..90b4fb07 100644 --- a/rsconcept/frontend/src/context/UsersContext.tsx +++ b/rsconcept/frontend/src/context/UsersContext.tsx @@ -30,7 +30,7 @@ export const UsersState = ({ children }: UsersStateProps) => { const getUserLabel = (userID?: number) => { const user = users.find(({ id }) => id === userID) if (user == null) { - return (userID !== undefined ? userID.toString() : 'Отсутствует'); + return (userID ? userID.toString() : 'Отсутствует'); } const hasFirstName = user.first_name != null && user.first_name !== ''; const hasLastName = user.last_name != null && user.last_name !== ''; @@ -51,7 +51,7 @@ export const UsersState = ({ children }: UsersStateProps) => { await getActiveUsers({ showError: true, onError: () => { setUsers([]); }, - onSucccess: response => { setUsers(response.data); } + onSuccess: response => { setUsers(response.data); } }); }, [setUsers] ) diff --git a/rsconcept/frontend/src/hooks/useCheckExpression.ts b/rsconcept/frontend/src/hooks/useCheckExpression.ts index 41da9220..cf6cea0a 100644 --- a/rsconcept/frontend/src/hooks/useCheckExpression.ts +++ b/rsconcept/frontend/src/hooks/useCheckExpression.ts @@ -20,7 +20,7 @@ function useCheckExpression({ schema }: { schema?: IRSForm }) { showError: true, setLoading, onError: error => { setError(error); }, - onSucccess: (response) => { + onSuccess: (response) => { setParseData(response.data); if (onSuccess) onSuccess(response); } diff --git a/rsconcept/frontend/src/hooks/useNewRSForm.ts b/rsconcept/frontend/src/hooks/useNewRSForm.ts index 63741fee..5a6b7e44 100644 --- a/rsconcept/frontend/src/hooks/useNewRSForm.ts +++ b/rsconcept/frontend/src/hooks/useNewRSForm.ts @@ -22,7 +22,7 @@ function useNewRSForm() { showError: true, setLoading, onError: error => { setError(error); }, - onSucccess: response => { onSuccess(response.data.id); } + onSuccess: response => { onSuccess(response.data.id); } }); } diff --git a/rsconcept/frontend/src/hooks/useRSFormDetails.ts b/rsconcept/frontend/src/hooks/useRSFormDetails.ts index 79d3d58d..294b3633 100644 --- a/rsconcept/frontend/src/hooks/useRSFormDetails.ts +++ b/rsconcept/frontend/src/hooks/useRSFormDetails.ts @@ -25,7 +25,7 @@ export function useRSFormDetails({ target }: { target?: string }) { showError: true, setLoading: setCustomLoading ?? setLoading, onError: error => { setInnerSchema(undefined); setError(error); }, - onSucccess: (response) => { setSchema(response.data); } + onSuccess: (response) => { setSchema(response.data); } }); }, [target]); diff --git a/rsconcept/frontend/src/hooks/useRSForms.ts b/rsconcept/frontend/src/hooks/useRSForms.ts index 7fe91040..13fb865b 100644 --- a/rsconcept/frontend/src/hooks/useRSForms.ts +++ b/rsconcept/frontend/src/hooks/useRSForms.ts @@ -24,7 +24,7 @@ export function useRSForms() { showError: true, setLoading, onError: error => { setError(error); }, - onSucccess: response => { setRSForms(response.data); } + onSuccess: response => { setRSForms(response.data); } }); }, []); diff --git a/rsconcept/frontend/src/hooks/useUserProfile.ts b/rsconcept/frontend/src/hooks/useUserProfile.ts index d86b3344..61f3f5fd 100644 --- a/rsconcept/frontend/src/hooks/useUserProfile.ts +++ b/rsconcept/frontend/src/hooks/useUserProfile.ts @@ -13,11 +13,12 @@ export function useUserProfile() { async () => { setError(undefined); setUser(undefined); + await getProfile({ showError: true, setLoading, onError: error => { setError(error); }, - onSucccess: response => { setUser(response.data); } + onSuccess: response => { setUser(response.data); } }); }, [setUser] ) diff --git a/rsconcept/frontend/src/pages/RSFormsPage/RSFormsTable.tsx b/rsconcept/frontend/src/pages/RSFormsPage/RSFormsTable.tsx index 769bfbe6..00a7d844 100644 --- a/rsconcept/frontend/src/pages/RSFormsPage/RSFormsTable.tsx +++ b/rsconcept/frontend/src/pages/RSFormsPage/RSFormsTable.tsx @@ -10,7 +10,7 @@ interface RSFormsTableProps { schemas: IRSForm[] } -function RSFormsTable({schemas}: RSFormsTableProps) { +function RSFormsTable({ schemas }: RSFormsTableProps) { const navigate = useNavigate(); const intl = useIntl(); const { getUserLabel } = useUsers(); diff --git a/rsconcept/frontend/src/pages/UserProfilePage/UserProfile.tsx b/rsconcept/frontend/src/pages/UserProfilePage/UserProfile.tsx index fb594591..92861952 100644 --- a/rsconcept/frontend/src/pages/UserProfilePage/UserProfile.tsx +++ b/rsconcept/frontend/src/pages/UserProfilePage/UserProfile.tsx @@ -1,14 +1,15 @@ -import { type IUserProfile } from '../../utils/models'; +import { useUserProfile } from '../../hooks/useUserProfile'; -interface UserProfileProps { - profile: IUserProfile -} - -export function UserProfile({ profile }: UserProfileProps) { +export function UserProfile() { + const { user } = useUserProfile(); + console.log(user) return ( -
-

username: {profile.username}

-

email: {profile.email}

+
+

Логин: {user?.username ?? 'Логин'}

+

Имя: {user?.first_name ?? 'Имя'}

+

Фамилия: {user?.last_name ?? 'Фамилия'}

+

Электронная почта: {user?.email ?? ''}

+
); } diff --git a/rsconcept/frontend/src/pages/UserProfilePage/index.tsx b/rsconcept/frontend/src/pages/UserProfilePage/index.tsx index 70046401..a0525bc8 100644 --- a/rsconcept/frontend/src/pages/UserProfilePage/index.tsx +++ b/rsconcept/frontend/src/pages/UserProfilePage/index.tsx @@ -10,7 +10,7 @@ function UserProfilePage() {
{ loading && } { error && } - { user && } + { user && }
); } diff --git a/rsconcept/frontend/src/utils/backendAPI.ts b/rsconcept/frontend/src/utils/backendAPI.ts index de8158ad..f9121c95 100644 --- a/rsconcept/frontend/src/utils/backendAPI.ts +++ b/rsconcept/frontend/src/utils/backendAPI.ts @@ -9,7 +9,7 @@ import { type ICurrentUser, type IRSForm, type IUserInfo, type IUserProfile } fr export type BackendCallback = (response: AxiosResponse) => void; export interface IFrontRequest { - onSucccess?: BackendCallback + onSuccess?: BackendCallback onError?: (error: ErrorInfo) => void setLoading?: (loading: boolean) => void showError?: boolean @@ -182,7 +182,7 @@ async function AxiosGet({ endpoint, request, title }: IAxiosRequest) axios.get(endpoint) .then((response) => { if (request?.setLoading) request?.setLoading(false); - if (request?.onSucccess) request.onSucccess(response); + if (request?.onSuccess) request.onSuccess(response); }) .catch((error) => { if (request?.setLoading) request?.setLoading(false); @@ -197,7 +197,7 @@ async function AxiosGetBlob({ endpoint, request, title }: IAxiosRequest) { axios.get(endpoint, { responseType: 'blob' }) .then((response) => { if (request?.setLoading) request?.setLoading(false); - if (request?.onSucccess) request.onSucccess(response); + if (request?.onSuccess) request.onSuccess(response); }) .catch((error) => { if (request?.setLoading) request?.setLoading(false); @@ -212,7 +212,7 @@ async function AxiosPost({ endpoint, request, title }: IAxiosRequest) { axios.post(endpoint, request?.data) .then((response) => { if (request?.setLoading) request?.setLoading(false); - if (request?.onSucccess) request.onSucccess(response); + if (request?.onSuccess) request.onSuccess(response); }) .catch((error) => { if (request?.setLoading) request?.setLoading(false); @@ -227,7 +227,7 @@ async function AxiosDelete({ endpoint, request, title }: IAxiosRequest) { axios.delete(endpoint) .then((response) => { if (request?.setLoading) request?.setLoading(false); - if (request?.onSucccess) request.onSucccess(response); + if (request?.onSuccess) request.onSuccess(response); }) .catch((error) => { if (request?.setLoading) request?.setLoading(false); @@ -242,7 +242,7 @@ async function AxiosPatch({ endpoint, request, title }: IAxiosReques axios.patch(endpoint, request?.data) .then((response) => { if (request?.setLoading) request?.setLoading(false); - if (request?.onSucccess) request.onSucccess(response); + if (request?.onSuccess) request.onSuccess(response); return response.data; }) .catch((error) => {