-
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.
- Loading branch information
Showing
14 changed files
with
159 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
npm run build:prod | ||
npm run lint:ts | ||
npm run lint:scss | ||
npm run test:unit | ||
npm run storybook:build | ||
npm run test:ui | ||
#. "$(dirname "$0")/_/husky.sh" | ||
# | ||
#npm run build:prod | ||
#npm run lint:ts | ||
#npm run lint:scss | ||
#npm run test:unit | ||
#npm run storybook:build | ||
#npm run test:ui | ||
|
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,8 +1,10 @@ | ||
import { CounterSchema } from 'entities/Counter'; | ||
import { UserSchema } from 'entities/User'; | ||
import { LoginSchema } from 'features/AuthByUsername'; | ||
|
||
export interface StateSchema { | ||
counter: CounterSchema; | ||
user: UserSchema; | ||
loginForm: LoginSchema | ||
|
||
} |
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 +1,3 @@ | ||
export { LoginModal } from './ui/LoginModal/LoginModal'; | ||
export { LoginSchema } from './model/types/loginSchema'; | ||
export { loginReducer } from './model/slice/loginSlice'; |
3 changes: 3 additions & 0 deletions
3
src/features/AuthByUsername/model/selectors/getLoginState/getLoginState.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,3 @@ | ||
import { StateSchema } from 'app/providers/StoreProvider'; | ||
|
||
export const getLoginState = (state: StateSchema) => state?.loginForm; |
28 changes: 28 additions & 0 deletions
28
src/features/AuthByUsername/model/services/loginByUsername/loginByUsername.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,28 @@ | ||
import { createAsyncThunk } from '@reduxjs/toolkit'; | ||
import axios from 'axios'; | ||
import { User } from 'entities/User'; | ||
|
||
interface LoginByUsernameProps { | ||
username: string; | ||
password: string | ||
} | ||
|
||
export const loginByUsername = createAsyncThunk< | ||
User, | ||
LoginByUsernameProps, | ||
{ rejectValue: string } | ||
>('login/loginByUsername', async (authData, thunkAPI) => { | ||
try { | ||
const response = await axios.post<User>('http://localhost:8000/login', { | ||
authData, | ||
}); | ||
if (!response.data) { | ||
throw new Error(); | ||
} | ||
|
||
return response.data; | ||
} catch (error) { | ||
console.log(error); | ||
return thunkAPI.rejectWithValue('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,40 @@ | ||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'; | ||
import { LoginSchema } from 'features/AuthByUsername/model/types/loginSchema'; | ||
import { loginByUsername } from '../services/loginByUsername/loginByUsername'; | ||
|
||
const initialState: LoginSchema = { | ||
isLoading: false, | ||
username: '', | ||
password: '', | ||
}; | ||
|
||
export const loginSlice = createSlice({ | ||
name: 'login', | ||
initialState, | ||
reducers: { | ||
setUsername: (state, action: PayloadAction<string>) => { | ||
state.username = action.payload; | ||
}, | ||
setPassword: (state, action: PayloadAction<string>) => { | ||
state.password = action.payload; | ||
}, | ||
|
||
}, | ||
extraReducers: (builder) => { | ||
builder | ||
.addCase(loginByUsername.pending, (state) => { | ||
state.error = undefined; | ||
state.isLoading = true; | ||
}) | ||
.addCase(loginByUsername.fulfilled, (state, action) => { | ||
state.isLoading = false; | ||
}) | ||
.addCase(loginByUsername.rejected, (state, action) => { | ||
state.isLoading = false; | ||
state.error = action.payload; | ||
}); | ||
}, | ||
}); | ||
|
||
export const { actions: loginActions } = loginSlice; | ||
export const { reducer: loginReducer } = loginSlice; |
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 interface LoginSchema { | ||
username: string; | ||
password: string; | ||
isLoading: boolean; | ||
error?: 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
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 |
---|---|---|
|
@@ -67,3 +67,7 @@ | |
.size_xl { | ||
font: var(--font-m); | ||
} | ||
|
||
.isDisabled { | ||
opacity: 0.5; | ||
} |
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