Skip to content

Commit

Permalink
add profile, optimization render
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMelior committed Apr 3, 2024
1 parent 813f2d3 commit 678a27c
Show file tree
Hide file tree
Showing 72 changed files with 840 additions and 492 deletions.
17 changes: 17 additions & 0 deletions app/[profile]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { ProfilePage } from '@/views/ProfilePage';
import { Metadata } from 'next';
import { FC } from 'react';

export const metadata: Metadata = {
title: 'Melior Gift - Профиль',
};

export interface ProfilePageProps {
params: { profile: string };
}

const Profile: FC<ProfilePageProps> = ({ params }) => {
return <ProfilePage params={params} />;
};

export default Profile;
5 changes: 5 additions & 0 deletions app/not-found.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { NotFoundPage } from '@/views';
import { Metadata } from 'next';
import { FC } from 'react';

export const metadata: Metadata = {
title: 'Melior Gift - Несуществующая страница 404',
};

const NotFound: FC = () => {
return <NotFoundPage />;
};
Expand Down
6 changes: 0 additions & 6 deletions app/product/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ export interface ProductPageProps {
params: { id: string };
}

// export async function generateStaticParams() {
// return productData.map((post) => ({
// product: post.id,
// }));
// }

const Product: FC<ProductPageProps> = ({ params }) => {
return <ProductPage params={params} />;
};
Expand Down
29 changes: 28 additions & 1 deletion json-server/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,32 @@
"username": "admin",
"password": "123"
}
]
],
"reviews": [
{
"id": 1,
"userId": 1,
"rating": 5,
"comment": "good",
"passed": true
}
],
"profile": {
"id": 1,
"private": false,
"email": "mark.melior@yandex.com",
"phone": "9834956634",
"first": "Mark",
"last": "Melior",
"age": 19,
"currency": "USD",
"country": "Russia",
"city": "Krasnodar",
"username": "MarkMelior",
"avatar": "ava.jpg",
"sex": "male",
"status": "active",
"favorites": [1],
"history": []
}
}
2 changes: 2 additions & 0 deletions src/app/providers/StoreProvider/config/RootState.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ProfileState } from '@/entities/Profile';
import { UserState } from '@/entities/User';
import { LoginState } from '@/features/Auth';
import { SearchState } from '@/features/Search';
Expand All @@ -18,6 +19,7 @@ export interface RootState {
sort?: SortState;
loginForm?: LoginState;
search?: SearchState;
profile?: ProfileState;
}

export type RootStateKey = keyof RootState;
Expand Down
2 changes: 1 addition & 1 deletion src/db.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ! IS TEMPORARY DATA FOR TESTING
import { ProductDataProps } from './shared/types/product';
import { ProductDataProps } from './entities/Product/model/types/product';

export const productData: ProductDataProps[] = [
{
Expand Down
12 changes: 12 additions & 0 deletions src/entities/Product/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Card } from '@nextui-org/react';
import {
MarketType,
MarketsProductData,
ProductDataProps,
} from './model/types/product';
import { CardWide } from './ui/CardWide/CardWide';
import { Cards, CardsProps } from './ui/Cards/Cards';

export { Card, CardWide, Cards };

export type { CardsProps, MarketType, MarketsProductData, ProductDataProps };
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FilterSortProps } from '@/features/Sorts';
import { Currency } from './localization';
import { Currency } from '@/shared/types/localization';

export interface ProductDataProps {
id: number;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
'use client';

import { ProductDataProps } from '@/entities/Product/model/types/product';
import { HeartIcon } from '@/shared/assets/icon/Heart';
import { ReviewIcon } from '@/shared/assets/icon/Review';
import { StarIcon } from '@/shared/assets/icon/Star';
import { Markets, MediaSize } from '@/shared/const';
import { convertCurrency, productLink } from '@/shared/lib/features';
import { useLocalstorageArray } from '@/shared/lib/hooks';
import { LocalstorageKeys } from '@/shared/types/localstorage';
import { ProductDataProps } from '@/shared/types/product';
import { Button } from '@/shared/ui/Button';
import { Tooltip } from '@nextui-org/react';
import cn from 'clsx';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { convertCurrency } from '@/shared/lib/features';
import Image from 'next/image';
import { FC } from 'react';
import { FC, memo } from 'react';
import { CardProps } from '../Card/Card';
import cls from './CardWide.module.scss';

export const CardWide: FC<CardProps> = ({ data }) => {
export const CardWide: FC<CardProps> = memo(({ data }) => {
const convertedPrice = convertCurrency(data.markets[0].price);
const convertedOldPrice = convertCurrency(data.markets[0].oldPrice);

Expand Down Expand Up @@ -57,4 +57,4 @@ export const CardWide: FC<CardProps> = ({ data }) => {
</div>
</div>
);
};
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';

import { ProductDataProps } from '@/shared/types/product';
import { FC } from 'react';
import { ProductDataProps } from '@/entities/Product/model/types/product';
import { FC, memo } from 'react';
import 'swiper/css/pagination';
import { Card } from '../Card/Card';
import cls from './Cards.module.scss';
Expand All @@ -11,7 +11,7 @@ export interface CardsProps {
size?: 'sm' | 'md';
}

export const Cards: FC<CardsProps> = ({ data, size }) => {
export const Cards: FC<CardsProps> = memo(({ data, size }) => {
if (!data) return null;

return (
Expand All @@ -21,4 +21,4 @@ export const Cards: FC<CardsProps> = ({ data, size }) => {
))}
</div>
);
};
});
24 changes: 24 additions & 0 deletions src/entities/Profile/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { profileActions, profileReducer } from './model/slice/profileSlice';
import {
ConfidentialityProfile,
Profile,
ProfileState,
} from './model/types/profile';
import {
GameBusiness,
GameConfidentialityProfile,
GameProfile,
GameProfileState,
} from './model/types/profileGame';

export { profileActions, profileReducer };

export type {
ConfidentialityProfile,
GameBusiness,
GameConfidentialityProfile,
GameProfile,
GameProfileState,
Profile,
ProfileState,
};
18 changes: 18 additions & 0 deletions src/entities/Profile/model/slice/profileSlice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { createSlice } from '@reduxjs/toolkit';
import { ProfileState } from '../types/profile';

export const profileInitialState: ProfileState = {
readonly: true,
isLoading: false,
error: undefined,
data: undefined,
};

export const profileSlice = createSlice({
name: 'profile',
initialState: profileInitialState,
reducers: {},
});

export const { actions: profileActions } = profileSlice;
export const { reducer: profileReducer } = profileSlice;
37 changes: 37 additions & 0 deletions src/entities/Profile/model/types/profile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Country, Currency } from '@/shared/types/localization';

export type Gender = 'male' | 'female';
export type Status = 'online' | 'offline' | 'busy' | 'invisible' | 'away';
export type ConfidentialityParams = 'private' | 'public' | 'friend';

export interface Profile {
id: number;
private: boolean;
email: string;
phone: string;
first: string;
last: string;
age: number;
currency: Currency;
country: Country;
city: string;
username: string;
avatar: string;
sex: Gender;
status: Status;
favorites: number[];
history: number[];
confidentiality?: ConfidentialityProfile;
gameId?: number;
}

export interface ConfidentialityProfile {
all: ConfidentialityParams;
}

export interface ProfileState {
data?: Profile;
isLoading: boolean;
error?: string;
readonly: boolean;
}
28 changes: 28 additions & 0 deletions src/entities/Profile/model/types/profileGame.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ConfidentialityParams } from './profile';

export interface GameProfile {
id: number;
cash: number;
casinoWin: number;
casinoLoss: number;
businessId: number;
confidentiality?: GameConfidentialityProfile;
}

export interface GameBusiness {
id: number;
name: string;
description: string;
income: number;
image: string;
}

export interface GameConfidentialityProfile {
all: ConfidentialityParams;
}

export interface GameProfileState {
data?: GameProfile;
isLoading: boolean;
error?: string;
}
47 changes: 37 additions & 10 deletions src/features/Auth/ui/ModalLogin/ModalLogin.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
'use client';

import { Notification } from '@/entities/Notification';
import { CheckIcon } from '@/shared/assets/icon/Check';
import { MailIcon } from '@/shared/assets/icon/Mail';
import { PasswordIcon } from '@/shared/assets/icon/Password';
import { UserIcon } from '@/shared/assets/icon/User';
import { DynamicModuleLoader, ReducersList } from '@/shared/lib/components';
import { useAppDispatch } from '@/shared/lib/hooks';
import { Button } from '@/shared/ui/Button';
import { Input } from '@/shared/ui/Input';
import {
Expand All @@ -19,8 +22,8 @@ import {
import Image from 'next/image';
import Link from 'next/link';
import { usePathname, useSearchParams } from 'next/navigation';
import { FC, memo, useCallback, useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { FC, useCallback, useMemo, useState } from 'react';
import { useSelector } from 'react-redux';
import { getLoginState } from '../../model/selector/getLoginState/getLoginState';
import { loginByUsername } from '../../model/service/loginByUsername/loginByUsername';
import { loginActions, loginReducer } from '../../model/slice/loginSlice';
Expand All @@ -35,11 +38,11 @@ const initialReducers: ReducersList = {
loginForm: loginReducer,
};

const ModalLogin: FC<ModalLoginProps> = memo(({ isOpen, onOpenChange }) => {
const ModalLogin: FC<ModalLoginProps> = ({ isOpen, onOpenChange }) => {
const searchParams = useSearchParams();
const isRegistration = searchParams.get('state') === 'sign-up';

const dispatch = useDispatch();
const dispatch = useAppDispatch();
const { password, username, error, isLoading } =
useSelector(getLoginState) || {};

Expand All @@ -57,16 +60,23 @@ const ModalLogin: FC<ModalLoginProps> = memo(({ isOpen, onOpenChange }) => {
[dispatch],
);

const onLoginClick = useCallback(() => {
// @ts-ignore
dispatch(loginByUsername({ username, password }));
}, [dispatch, password, username]);
const [showNotification, setShowNotification] = useState(false);

const onLoginClick = useCallback(async () => {
// @ts-ignore fix
const result = await dispatch(loginByUsername({ username, password }));

if (result.meta.requestStatus === 'fulfilled') {
onOpenChange(false);
setShowNotification(true);
}
}, [dispatch, onOpenChange, password, username]);

const renderLogin = useMemo(() => {
return (
<Tab
as={Link}
// @ts-ignore
// @ts-ignore fix
scroll={false}
href={'?state=login'}
key='login'
Expand Down Expand Up @@ -206,8 +216,25 @@ const ModalLogin: FC<ModalLoginProps> = memo(({ isOpen, onOpenChange }) => {
)}
</ModalContent>
</Modal>
{showNotification && (
<Notification
message={`${username}, вы успешно авторизовались!`}
duration={5000}
placement='top'
onClose={() => setShowNotification(false)}
closeOnClick
startContent={
<CheckIcon
width={16}
height={16}
color='hsl(var(--gift-success))'
isSelected
/>
}
/>
)}
</DynamicModuleLoader>
);
});
};

export default ModalLogin;
Loading

0 comments on commit 678a27c

Please sign in to comment.