File tree Expand file tree Collapse file tree 5 files changed +11
-8
lines changed
Expand file tree Collapse file tree 5 files changed +11
-8
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import { AuthCredentials } from "../model/types";
33
44export const authApiSlice = apiSlice . injectEndpoints ( {
55 endpoints : ( builder ) => ( {
6- register : builder . mutation < TokenPair , AuthCredentials > ( {
6+ register : builder . mutation < void , AuthCredentials > ( {
77 query : ( credentials : AuthCredentials ) => ( {
88 url : "/users/register" ,
99 method : "POST" ,
Original file line number Diff line number Diff line change @@ -75,6 +75,6 @@ export const mapAuthApiError = (
7575
7676 return {
7777 title : "Не удалось выполнить запрос" ,
78- description : "Попробуйте повторить попытку или обратитесь к админу ." ,
78+ description : "Попробуйте еще раз ." ,
7979 } ;
8080} ;
Original file line number Diff line number Diff line change @@ -32,9 +32,6 @@ const slice = createSlice({
3232 . addMatcher ( authApiSlice . endpoints . login . matchFulfilled , ( state , { payload } ) =>
3333 applyTokens ( state , payload ) ,
3434 )
35- . addMatcher ( authApiSlice . endpoints . register . matchFulfilled , ( state , { payload } ) =>
36- applyTokens ( state , payload ) ,
37- )
3835 . addMatcher ( userApiSlice . endpoints . getMe . matchFulfilled , ( state , { payload } ) => {
3936 state . user = payload ;
4037 } ) ;
Original file line number Diff line number Diff line change 1- import { useRegisterMutation } from "features/auth/api/authApi" ;
1+ import { useLoginMutation , useRegisterMutation } from "features/auth/api/authApi" ;
22import { registrationStruct } from "features/auth/model/authStruct" ;
33import { mapAuthApiError , mapValidationError } from "features/auth/lib/mapAuthError" ;
44import { FormEvent , FormEventHandler , useState } from "react" ;
@@ -22,7 +22,10 @@ export const RegisterForm = ({ onStatusChange }: RegisterFormProps) => {
2222
2323 const navigate = useNavigate ( ) ;
2424
25- const [ register , { isLoading } ] = useRegisterMutation ( ) ;
25+ const [ register , { isLoading : isRegisterLoading } ] = useRegisterMutation ( ) ;
26+ const [ login , { isLoading : isLoginLoading } ] = useLoginMutation ( ) ;
27+
28+ const isLoading = isLoginLoading || isRegisterLoading ;
2629
2730 const onSubmit : FormEventHandler < HTMLFormElement > = async ( e : FormEvent < HTMLFormElement > ) => {
2831 e . preventDefault ( ) ;
@@ -41,9 +44,13 @@ export const RegisterForm = ({ onStatusChange }: RegisterFormProps) => {
4144
4245 try {
4346 await register ( result ) . unwrap ( ) ;
47+ await login ( { nickname, password } ) . unwrap ( ) ;
48+
4449 onStatusChange ?.( null ) ;
50+
4551 navigate ( AppRoutes . INDEX ) ;
4652 } catch ( err ) {
53+ console . log ( err ) ;
4754 const payload = mapAuthApiError ( err ) ;
4855 onStatusChange ?.( payload ) ;
4956 }
Original file line number Diff line number Diff line change 44 align-items : center ;
55 justify-content : center ;
66 gap : 1.5em ;
7- min-height : 100% ;
87}
98
109.statusBanner {
You can’t perform that action at this time.
0 commit comments