-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add shadui sonner, add tailwind, add authSlice, add authThunk, update…
… userAuthForm
- Loading branch information
Showing
46 changed files
with
922 additions
and
256 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"$schema": "https://ui.shadcn.com/schema.json", | ||
"style": "new-york", | ||
"rsc": false, | ||
"tsx": true, | ||
"tailwind": { | ||
"config": "tailwind.config.js", | ||
"css": "src/shared/styles/global-tailwind.css", | ||
"baseColor": "neutral", | ||
"cssVariables": true, | ||
"prefix": "" | ||
}, | ||
"aliases": { | ||
"components": "@/shared/ui-shad", | ||
"utils": "@/shared/lib" | ||
} | ||
} |
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
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
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
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 |
---|---|---|
|
@@ -14,4 +14,6 @@ i18n | |
interpolation: { | ||
escapeValue: false, | ||
}, | ||
}); | ||
}); | ||
|
||
export const i18nConfig = i18n; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './config'; | ||
export * from './providers'; | ||
export * from './slices'; | ||
export * from './slices'; | ||
export * from './types/thunkDispatch.type.ts'; |
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,6 @@ | ||
export * from './slice/auth.slice.ts'; | ||
export * from './types/auth.schema.ts'; | ||
export * from './thunks/authByUsername.ts'; | ||
export * from './selectors/getAuthPending.ts'; | ||
export * from './selectors/getAuthState.ts'; | ||
export * from './selectors/getAuthError.ts'; |
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,5 @@ | ||
import { createSelector } from '@reduxjs/toolkit'; | ||
import { getAuthState } from '@/app/redux/slices/auth/selectors/getAuthState.ts'; | ||
|
||
|
||
export const getAuthError = createSelector(getAuthState, (state) => state.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,5 @@ | ||
import { createSelector } from '@reduxjs/toolkit'; | ||
import { getAuthState } from '@/app/redux/slices/auth/selectors/getAuthState.ts'; | ||
|
||
|
||
export const getAuthPending = createSelector(getAuthState, (state) => state.isPending); |
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 @@ | ||
import { GlobalStoreSchema } from '@/app'; | ||
|
||
|
||
export const getAuthState = (state: GlobalStoreSchema) => state.auth; |
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,40 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
import { AuthSchema } from '..'; | ||
import { authByUsername } from '@/app/redux/slices/auth/thunks/authByUsername.ts'; | ||
import { toast } from 'sonner'; | ||
import { i18nConfig } from '@/app'; | ||
|
||
|
||
const initialState: AuthSchema = { | ||
isPending: false, | ||
error : null, | ||
}; | ||
|
||
export const authSlice = createSlice({ | ||
name : 'auth', | ||
initialState : initialState, | ||
reducers : {}, | ||
extraReducers: (builder) => { | ||
builder.addCase(authByUsername.fulfilled, (state) => { | ||
state.isPending = false; | ||
state.error = null; | ||
toast(i18nConfig.t('auth_success_title'), { duration: 3000 }); | ||
}); | ||
builder.addCase(authByUsername.pending, (state) => { | ||
state.isPending = true; | ||
state.error = null; | ||
}); | ||
builder.addCase(authByUsername.rejected, (state, action) => { | ||
state.isPending = false; | ||
state.error = action.payload ?? { | ||
code : 500, | ||
message: 'Unknown error', | ||
}; | ||
toast(i18nConfig.t('auth_error_title'), { | ||
duration: 5000, description: state.error.message, | ||
}); | ||
}); | ||
}, | ||
}); | ||
|
||
export const { actions: authActions, reducer: authReducer } = authSlice; |
Empty file.
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,40 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
import { AuthErrorType, User } from '@/app'; | ||
import axios, { AxiosError } from 'axios'; | ||
|
||
|
||
export type AuthByUsernameProps = { | ||
username: string; | ||
password: string; | ||
remember?: boolean; | ||
} | ||
|
||
export type AuthThunkApiConfig = { | ||
rejectValue: AuthErrorType | null; | ||
} | ||
|
||
export type ServerErrorResponse = { | ||
message: string; | ||
} | ||
|
||
export const authByUsername = createAsyncThunk<User, AuthByUsernameProps, AuthThunkApiConfig>( | ||
'auth/byUsername', | ||
async (authData, thunkAPI) => { | ||
try { | ||
return await axios.post('http://localhost:8000/login', authData); | ||
} catch (e: any) { | ||
const error: AxiosError<ServerErrorResponse, any> = e as AxiosError<ServerErrorResponse, any>; | ||
if (error?.response) { | ||
return thunkAPI.rejectWithValue({ | ||
code : error.response.status, | ||
message: error.response.data.message, | ||
}); | ||
} else { | ||
return thunkAPI.rejectWithValue({ | ||
code : 500, | ||
message: e?.message ?? 'Unknown 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,9 @@ | ||
export type AuthErrorType = { | ||
code: number; | ||
message: string; | ||
} | ||
|
||
export type AuthSchema = { | ||
isPending: boolean; | ||
error: AuthErrorType | null; | ||
} |
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,2 @@ | ||
export * from './user'; | ||
export * from './user'; | ||
export * from './auth'; |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { User } from '@/global/types/user'; | ||
import { User } from '@/app'; | ||
|
||
|
||
export type UserSchema = { | ||
|
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,5 @@ | ||
import { ThunkDispatch } from '@reduxjs/toolkit'; | ||
import { GlobalStoreSchema } from '@/app'; | ||
|
||
|
||
export type ThunkDispatchType = ThunkDispatch<GlobalStoreSchema, any, any>; |
7 changes: 2 additions & 5 deletions
7
src/app/theme/ui/buttons/ToggleThemeButton/_e2e/ToggleThemeButton.e2e-test.tsx
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './types/validator.ts'; | ||
export * from './user/login.validators.ts'; | ||
export * from './user/password.validators.ts'; |
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 type Validator<Type> = (value: Type) => string; |
Oops, something went wrong.