Skip to content

Commit

Permalink
userdata
Browse files Browse the repository at this point in the history
  • Loading branch information
ElPastel committed Nov 26, 2023
1 parent ae82184 commit a7c0d2b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
11 changes: 8 additions & 3 deletions src/components/UserContactsForm.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
import { Button, Form, Input } from 'antd';
import { useAppSelector } from '../store';
import { selectCurrentUser } from '../store/auth/authSlice';

type FieldType = {
email?: string;
phone?: string;
};

function UserContactsForm() {
const user = useAppSelector(selectCurrentUser);

return (
<Form
name="userdata"
layout="vertical"
className="flex flex-wrap gap-8"
className="flex flex-wrap items-end justify-between"
autoComplete="off"
requiredMark={false}
initialValues={{ email: user?.email || '' }}
>
<div className="flex flex-wrap gap-3">
<Form.Item<FieldType>
label={<p className="font-nunito text-sm text-[#242424]">Email</p>}
name="email"
className="w-[12.125rem]"
className="w-[29rem]"
rules={[
{
required: true,
message: 'Пожалуйста введите свою почту',
},
]}
>
<Input className="border-gray-400" />
<Input className="w-[29rem] border-gray-400" />
</Form.Item>

<Form.Item<FieldType>
Expand Down
13 changes: 11 additions & 2 deletions src/components/UserNameForm.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
import { Button, Form, Input } from 'antd';
import { useAppSelector } from '../store';
import { selectCurrentUser } from '../store/auth/authSlice';

type FieldType = {
first_name?: string;
last_name?: string;
surname?: string;
mid_name?: string;
};

function UserNameForm() {
const user = useAppSelector(selectCurrentUser);

return (
<Form
name="userdata"
layout="vertical"
className="flex items-end gap-8"
autoComplete="off"
requiredMark={false}
initialValues={{
first_name: user?.first_name || '',
last_name: user?.last_name || '',
mid_name: user?.mid_name || '',
}}
>
<div className="flex flex-wrap gap-3">
<Form.Item<FieldType>
Expand Down Expand Up @@ -46,7 +55,7 @@ function UserNameForm() {

<Form.Item<FieldType>
label={<p className="font-nunito text-sm text-[#242424]">Отчество</p>}
name="surname"
name="mid_name"
className="w-[16.25rem]"
rules={[
{
Expand Down
9 changes: 6 additions & 3 deletions src/components/ui/ModalReg.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { Button, Form, Input } from 'antd';
import { ValidateErrorEntity } from 'rc-field-form/es/interface';
import { Link } from 'react-router-dom';
import { Link, useNavigate } from 'react-router-dom';
import { Routes } from '../../constants/routes';
import ArrowLeft from '../../assets/icons/ArrowLeft';
import { useAppDispatch } from '../../store';
import { registration } from '../../store/auth/authActions';

function ModalReg() {
const dispatch = useAppDispatch();
const navigate = useNavigate();

const onFinish = (values: { secrete_code: string }) => {
console.log(values);
dispatch(registration(values.secrete_code));
dispatch(registration(values.secrete_code)).then((data) => {
console.log(data);
navigate(Routes.PROFILE);
});
};

const onFinishFailed = (
Expand Down
4 changes: 3 additions & 1 deletion src/store/auth/authActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Token {
is_admin: boolean;
}
type TokenResponse = AxiosResponse<Token>;
type UserResponse = AxiosResponse<User>;

export const signInUser = createAsyncThunk(
'auth/signin',
Expand Down Expand Up @@ -66,9 +67,10 @@ export const getUser = createAsyncThunk(
async (_, { rejectWithValue }) => {
try {
const token = getToken();
const res = await axios.get<void, User>(`${BASE_URL}users/me`, {
const res = await axios.get<void, UserResponse>(`${BASE_URL}users/me`, {
headers: { Authorization: `Token ${token?.slice(1, -1)}` },
});
console.log(res.data);
return res;
} catch (e) {
return rejectWithValue(e);
Expand Down
2 changes: 1 addition & 1 deletion src/store/auth/extraReducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const buildGetUser = (builder: ActionReducerMapBuilder<AuthState>) =>
})
.addCase(getUser.fulfilled, (state, action) => {
state.userStatus = 'success';
state.user = action.payload;
state.user = action.payload.data;
state.isAuth = true;
state.userError = null;
})
Expand Down
8 changes: 7 additions & 1 deletion src/store/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ export interface Login {
password: string;
}

export type User = Omit<Registry, 'password'>;
export interface User {
email: string;
password: string;
first_name: string;
last_name: string;
mid_name?: string;
}

export interface AuthState {
user: User | null;
Expand Down

0 comments on commit a7c0d2b

Please sign in to comment.