mirror of
https://github.com/IRBorisov/ConceptPortal.git
synced 2025-06-26 04:50:36 +03:00
onSucccess->onSuccess
This commit is contained in:
parent
e7016aab21
commit
468de70465
|
@ -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); })
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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); }
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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]);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ export function useRSForms() {
|
|||
showError: true,
|
||||
setLoading,
|
||||
onError: error => { setError(error); },
|
||||
onSucccess: response => { setRSForms(response.data); }
|
||||
onSuccess: response => { setRSForms(response.data); }
|
||||
});
|
||||
}, []);
|
||||
|
||||
|
|
|
@ -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]
|
||||
)
|
||||
|
|
|
@ -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 (
|
||||
<div className='flex justify-center'>
|
||||
<p>username: {profile.username}</p>
|
||||
<p>email: {profile.email}</p>
|
||||
<div className='flex flex-col items-center justify-center px-2 py-2 border'>
|
||||
<p>Логин: {user?.username ?? 'Логин'}</p>
|
||||
<p>Имя: {user?.first_name ?? 'Имя'}</p>
|
||||
<p>Фамилия: {user?.last_name ?? 'Фамилия'}</p>
|
||||
<p>Электронная почта: {user?.email ?? ''}</p>
|
||||
<button className='px-2 py-1 bg-green-500 border' onClick={() => { console.log('123') } } >Сохранить</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ function UserProfilePage() {
|
|||
<div className='w-full'>
|
||||
{ loading && <Loader /> }
|
||||
{ error && <BackendError error={error} />}
|
||||
{ user && <UserProfile profile={user} /> }
|
||||
{ user && <UserProfile /> }
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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<ReturnType>({ endpoint, request, title }: IAxiosRequest)
|
|||
axios.get<ReturnType>(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<ReturnType>({ endpoint, request, title }: IAxiosReques
|
|||
axios.patch<ReturnType>(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) => {
|
||||
|
|
Loading…
Reference in New Issue
Block a user