Skip to content

Commit

Permalink
fix profile page & add update profile request & other fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stambekovbera committed Mar 13, 2024
1 parent 839d1c3 commit 6eb65ee
Show file tree
Hide file tree
Showing 37 changed files with 378 additions and 61 deletions.
Binary file modified .loki/reference/chrome_iphone7_pages_ProfilePage_Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_pages_ProfilePage_Light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_Modal_Primary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_iphone7_shared_Modal_Primary_Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_pages_ProfilePage_Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_pages_ProfilePage_Light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_shared_Modal_Primary.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified .loki/reference/chrome_laptop_shared_Modal_Primary_Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion extractedTranslations/en/profile.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"cancel_button_text": "cancel_button_text",
"edit_button_text": "",
"profile_age_input_placeholder": "profile_age_input_placeholder",
"profile_card_error_text": "profile_card_error_text",
"profile_card_error_title": "profile_card_error_title",
"profile_city_input_placeholder": "profile_city_input_placeholder",
"profile_edit_button_text": "",
"profile_firstname_input_placeholder": "profile_firstname_input_placeholder",
"profile_lastname_input_placeholder": "profile_lastname_input_placeholder",
"profile_title": ""
"profile_title": "",
"save_button_text": "save_button_text"
}
7 changes: 7 additions & 0 deletions extractedTranslations/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
"about_page": "about_page",
"authorization_error_text": "authorization_error_text",
"authorization_error_title": "authorization_error_title",
"cancel_button_text": "cancel_button_text",
"collapse": "collapse",
"counter-decrement": "counter-decrement",
"counter-increment": "counter-increment",
"counter-title": "counter-title",
"edit_button_text": "edit_button_text",
"language": "language",
"language_short": "language_short",
"login": "login",
Expand All @@ -17,11 +19,16 @@
"open-modal": "open-modal",
"page_error_message": "page_error_message",
"page_reload_text": "page_reload_text",
"profile_age_input_placeholder": "profile_age_input_placeholder",
"profile_card_error_text": "profile_card_error_text",
"profile_card_error_title": "profile_card_error_title",
"profile_city_input_placeholder": "profile_city_input_placeholder",
"profile_edit_button_text": "profile_edit_button_text",
"profile_firstname_input_placeholder": "profile_firstname_input_placeholder",
"profile_lastname_input_placeholder": "profile_lastname_input_placeholder",
"profile_navbar": "profile_navbar",
"profile_title": "profile_title",
"save_button_text": "save_button_text",
"throw_error": "throw_error",
"username": "username",
"userpass": "userpass"
Expand Down
7 changes: 7 additions & 0 deletions extractedTranslations/ru/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
"about_page": "about_page",
"authorization_error_text": "authorization_error_text",
"authorization_error_title": "authorization_error_title",
"cancel_button_text": "cancel_button_text",
"collapse": "collapse",
"counter-decrement": "counter-decrement",
"counter-increment": "counter-increment",
"counter-title": "counter-title",
"edit_button_text": "edit_button_text",
"language": "language",
"language_short": "language_short",
"login": "login",
Expand All @@ -17,11 +19,16 @@
"open-modal": "open-modal",
"page_error_message": "page_error_message",
"page_reload_text": "page_reload_text",
"profile_age_input_placeholder": "profile_age_input_placeholder",
"profile_card_error_text": "profile_card_error_text",
"profile_card_error_title": "profile_card_error_title",
"profile_city_input_placeholder": "profile_city_input_placeholder",
"profile_edit_button_text": "profile_edit_button_text",
"profile_firstname_input_placeholder": "profile_firstname_input_placeholder",
"profile_lastname_input_placeholder": "profile_lastname_input_placeholder",
"profile_navbar": "profile_navbar",
"profile_title": "profile_title",
"save_button_text": "save_button_text",
"throw_error": "throw_error",
"username": "username",
"userpass": "userpass"
Expand Down
2 changes: 1 addition & 1 deletion json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
"username": "kandaysbln",
"avatar": "https://avataaars.io/?avatarStyle=Circle&topType=LongHairNotTooLong&accessoriesType=Blank&hairColor=BrownDark&facialHairType=BeardMedium&facialHairColor=BrownDark&clotheType=CollarSweater&clotheColor=PastelBlue&eyeType=Surprised&eyebrowType=Default&mouthType=Smile&skinColor=Light"
}
}
}
7 changes: 5 additions & 2 deletions public/locales/en/profile.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"profile_title": "Profile",
"profile_edit_button_text": "Edit",
"profile_firstname_input_placeholder": "Your name",
"profile_lastname_input_placeholder": "Your lastname"
"profile_lastname_input_placeholder": "Your lastname",
"profile_card_error_title": "There was an error loading your profile",
"profile_card_error_text": "Try refreshing your profile page",
"profile_age_input_placeholder": "Your age",
"profile_city_input_placeholder": "Your city"
}
5 changes: 4 additions & 1 deletion public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"authorization_error_title": "Authorization error",
"authorization_error_text": "Wrong login or password",
"logout": "Logout",
"profile_navbar": "Profile"
"profile_navbar": "Profile",
"cancel_button_text": "Cancel",
"save_button_text": "Save",
"edit_button_text": "Edit"
}
7 changes: 5 additions & 2 deletions public/locales/ru/profile.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"profile_title": "Профиль",
"profile_edit_button_text": "Редактировать",
"profile_firstname_input_placeholder": "Ваше имя",
"profile_lastname_input_placeholder": "Ваша фамилия"
"profile_lastname_input_placeholder": "Ваша фамилия",
"profile_card_error_title": "Произошла ошибка при загрузке профиля",
"profile_card_error_text": "Попробуйте обновить страницу",
"profile_age_input_placeholder": "Ваш возраст",
"profile_city_input_placeholder": "Ваш город"
}
5 changes: 4 additions & 1 deletion public/locales/ru/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
"authorization_error_title": "Ошибка при авторизации",
"authorization_error_text": "Неверный логин или пароль",
"logout": "Выйти",
"profile_navbar": "Профиль"
"profile_navbar": "Профиль",
"cancel_button_text": "Отменить",
"save_button_text": "Сохранить",
"edit_button_text": "Редактировать"
}
2 changes: 1 addition & 1 deletion src/app/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ body {

.content-page {
display: flex;
gap: 30px;
}

.page-wrapper {
flex-grow: 1;
padding: 30px;
}
6 changes: 6 additions & 0 deletions src/entities/Profile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,11 @@ export { IProfile, IProfileSchema } from './model/types/profile';
export { profileReducer, profileActions } from './model/slice/profileSlice';

export { fetchProfileData } from './model/services/fetchProfileData/fetchProfileData';
export { updateProfileData } from './model/services/updateProfileData/updateProfileData';

export { ProfileCard } from './ui/ProfileCard/ProfileCard';

export { getProfileData } from './model/selectors/getProfileData/getProfileData';
export { getProfileIsLoading } from './model/selectors/getProfileIsLoading/getProfileIsLoading';
export { getProfileError } from './model/selectors/getProfileError/getProfileError';
export { getProfileReadonly } from './model/selectors/getProfileReadonly/getProfileReadonly';
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { IStateSchema } from 'shared/config/storeConfig/StateSchema';

export const getProfileForm = (state: IStateSchema) => state.profile?.form || undefined;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { IStateSchema } from 'shared/config/storeConfig/StateSchema';

export const getProfileReadonly = (state: IStateSchema) => state.profile?.readonly || false;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { createAsyncThunk } from '@reduxjs/toolkit';
import { IThunkConfig } from 'shared/config/storeConfig/StateSchema';
import { IProfile } from '../../types/profile';
import { getProfileForm } from '../../selectors/getProfileForm/getProfileForm';

export const updateProfileData= createAsyncThunk<IProfile, undefined, IThunkConfig<string>>(
'profile/updateProfileData',
async (_, thunkAPI) => {
const { extra, getState } = thunkAPI;
const formData = getProfileForm( getState() );

try {
const response = await extra.api.put<IProfile>( '/profile', formData );

thunkAPI.fulfillWithValue( response.data );

return response.data;
} catch (err) {
return thunkAPI.rejectWithValue( 'error' );
}
}
);
37 changes: 34 additions & 3 deletions src/entities/Profile/model/slice/profileSlice.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
import { createSlice } from '@reduxjs/toolkit';
import { IProfileSchema } from '../types/profile';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import { IProfile, IProfileSchema } from '../types/profile';
import { fetchProfileData } from '../services/fetchProfileData/fetchProfileData';
import { updateProfileData } from '../services/updateProfileData/updateProfileData';

const initialState: IProfileSchema = {
isLoading: false,
readonly: true,
error: undefined,
data: undefined,
form: undefined,
};

export const profileSlice = createSlice( {
name: 'profile',
initialState,
reducers: {},
reducers: {
setReadonly: (state, action: PayloadAction<boolean>) => {
state.readonly = action.payload;
},
cancelEdit: (state) => {
state.readonly = true;
state.form = state.data;
},
updateProfile: (state, action: PayloadAction<IProfile>) => {
state.form = {
...state.form,
...action.payload
};
},
},
extraReducers: (builder) => {
builder
.addCase( fetchProfileData.pending, (state) => {
Expand All @@ -22,12 +38,27 @@ export const profileSlice = createSlice( {
.addCase( fetchProfileData.fulfilled, (state, action) => {
state.isLoading = false;
state.data = action.payload;
state.form = action.payload;
state.error = undefined;
} )
.addCase( fetchProfileData.rejected, (state, action) => {
state.isLoading = false;
state.data = undefined;
state.error = action.payload;
} )
.addCase( updateProfileData.pending, (state) => {
state.isLoading = true;
state.error = undefined;
} )
.addCase( updateProfileData.fulfilled, (state, action) => {
state.isLoading = false;
state.data = action.payload;
state.form = action.payload;
state.error = undefined;
} )
.addCase( updateProfileData.rejected, (state, action) => {
state.isLoading = false;
state.error = action.payload;
} );
}
} );
Expand Down
17 changes: 9 additions & 8 deletions src/entities/Profile/model/types/profile.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { Country, Currency } from 'shared/const/common';

export interface IProfile {
firstname: string;
lastname: string;
age: number;
currency: Currency;
country: Country;
city: string;
username: string;
avatar: string;
firstname?: string;
lastname?: string;
age?: number;
currency?: Currency;
country?: Country;
city?: string;
username?: string;
avatar?: string;
}

export interface IProfileSchema {
data?: IProfile;
form?: IProfile;
isLoading: boolean;
error?: string;
readonly: boolean;
Expand Down
14 changes: 8 additions & 6 deletions src/entities/Profile/ui/ProfileCard/ProfileCard.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
border: 2px solid var(--inverted-bg-color);
}

.header {
display: flex;
align-items: center;
gap: 10px;
}

.body {
display: flex;
flex-direction: column;
Expand All @@ -20,3 +14,11 @@

.input {
}

.loading,
.error {
display: flex;
align-items: center;
justify-content: center;
height: 300px;
}
Loading

0 comments on commit 6eb65ee

Please sign in to comment.