Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprint#4 #53

Merged
merged 75 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
cba9489
fix: some minor fixes
LikeKugi Sep 4, 2023
ff7896d
feat: add update action types for update my customer
LikeKugi Sep 4, 2023
9a90c9e
feat: add change backend info with refetch
LikeKugi Sep 4, 2023
ce2157d
feat: add api endpoint
LikeKugi Sep 4, 2023
bd85a93
feat: validation and request for add new address
LikeKugi Sep 4, 2023
ada7deb
refactor: eslint fixes
LikeKugi Sep 4, 2023
e011382
chores: start password field
LikeKugi Sep 4, 2023
db2aa02
fix: edit user features works correct
LikeKugi Sep 5, 2023
7174ad6
fix: remove console log
LikeKugi Sep 5, 2023
c309d15
init: start about us page layout
Nargiza14 Sep 6, 2023
1a9e990
feat: add avatars and github links
Nargiza14 Sep 6, 2023
194f452
feat: add cards info
Nargiza14 Sep 6, 2023
d28ddb3
feat: add page background
Nargiza14 Sep 6, 2023
89b0f03
feat: swap button from detailed link to add to cart action in Product…
LikeKugi Sep 6, 2023
94123b6
update: change styles
Nargiza14 Sep 7, 2023
f8308f8
Merge pull request #42 from evgueniazet/sprint-4_catalog-page_enhance…
evgueniazet Sep 7, 2023
689083c
Merge pull request #41 from evgueniazet/sprint-3_user-page_manage-api
evgueniazet Sep 7, 2023
c692f85
Merge pull request #40 from evgueniazet/sprint-4_about-us-page_layout
evgueniazet Sep 7, 2023
99c165a
fix: return in useEffect filter params and move types to types folder
LikeKugi Sep 7, 2023
5546f31
feat: add pagination for lazy loading implementation
LikeKugi Sep 7, 2023
5cdfc02
feat: add pagination state in ProductsQuery
LikeKugi Sep 7, 2023
8d24d12
Merge pull request #43 from evgueniazet/sprint-4_catalog-page_lazy-lo…
LikeKugi Sep 8, 2023
97b47cd
refactor: change id on elements to useId hook
LikeKugi Sep 8, 2023
88a78e4
refactor: eslint fixes
LikeKugi Sep 8, 2023
0ca2854
feat: add session storage token flow
LikeKugi Sep 8, 2023
bcd959a
refactor: eslint fixes
LikeKugi Sep 8, 2023
18e331c
init: start basket page layout
Nargiza14 Sep 8, 2023
6399faa
Merge pull request #44 from evgueniazet/sprint-4_refactor-features
LikeKugi Sep 9, 2023
210dd02
feat: add empty cart page layout
Nargiza14 Sep 9, 2023
de2f39a
feat: add quantity btns
Nargiza14 Sep 9, 2023
0b7f03d
feat: add cart summary section
Nargiza14 Sep 9, 2023
cec0eff
feat: add cart api types and base query
LikeKugi Sep 9, 2023
43bbc28
feat: add delete cart api query
LikeKugi Sep 9, 2023
8b5561a
feat: add check out btn
Nargiza14 Sep 10, 2023
d6c0de0
feat: add create cart request on get active cart error response
LikeKugi Sep 10, 2023
366417a
feat: add promo code section
Nargiza14 Sep 10, 2023
24edb83
feat: add create slice
LikeKugi Sep 10, 2023
6c5d1fe
feat: add feature to put and remove product into cart
LikeKugi Sep 11, 2023
0517e66
refactor: eslint fixes
LikeKugi Sep 11, 2023
ffded85
refactor: eslint fixes
LikeKugi Sep 11, 2023
580c26b
fix: change package json
evgueniazet Sep 12, 2023
fdbb38a
Merge pull request #46 from evgueniazet/sprint-4_cart-flow
evgueniazet Sep 12, 2023
ad4692d
Merge pull request #45 from evgueniazet/sprint-4_basket-page_layout
evgueniazet Sep 12, 2023
b402652
init: start home page layout
Nargiza14 Sep 13, 2023
515107e
feat: add banner
Nargiza14 Sep 13, 2023
64a2e58
feat: add promo codes
Nargiza14 Sep 13, 2023
d5cf22c
feat: add info section
Nargiza14 Sep 14, 2023
278dbb0
feat: add footer.tsx file
Nargiza14 Sep 14, 2023
8de71a1
feat: add footer info
Nargiza14 Sep 14, 2023
7cbfae2
feat: add footer animation
Nargiza14 Sep 14, 2023
c9deae5
fix: change header logo
Nargiza14 Sep 14, 2023
bdb41c7
fix: refetch problems
LikeKugi Sep 14, 2023
01f8759
feat: add modifier for line items quantity in cart
LikeKugi Sep 14, 2023
d47dfcb
feat: add cart icon in header
LikeKugi Sep 14, 2023
bbc0570
feat: add and fixed layout for each line item in cart
LikeKugi Sep 14, 2023
d3d1759
refactor: eslint fixes
LikeKugi Sep 14, 2023
bdde3d1
Merge pull request #48 from evgueniazet/sprint-4_basket-features
evgueniazet Sep 15, 2023
9b76c28
Merge pull request #49 from evgueniazet/sprint-4_home-page_layout
evgueniazet Sep 15, 2023
2e125a1
fix: clear cart button fix
LikeKugi Sep 15, 2023
453fae9
fix: footer layout
LikeKugi Sep 15, 2023
28916af
refactor: remove console log
Sep 10, 2023
1cf0e04
fix: fix types in api
LikeKugi Sep 16, 2023
3139839
fix: discounts in product card
LikeKugi Sep 16, 2023
6eb86ec
feat: add discount codes on home page
LikeKugi Sep 16, 2023
f153222
refactor: eslint fixes
LikeKugi Sep 16, 2023
f32356d
feat: add query in basket discount form
LikeKugi Sep 17, 2023
15b1023
feat: add unit tests
Sep 17, 2023
fcfe917
feat: add subtotal price calculation
LikeKugi Sep 17, 2023
b5c85b9
feat: add subtotal and total prices in basket line items
LikeKugi Sep 17, 2023
f4049f8
refactor: eslint fixes
LikeKugi Sep 17, 2023
d9784fb
feat: add unit tests
Sep 18, 2023
ede6906
Merge pull request #51 from evgueniazet/sprint-4_basket_discounts
evgueniazet Sep 18, 2023
7bd05b1
feat: add unit tests
Sep 18, 2023
0021189
Merge branch 'release_basket-about_us' into sprint-4_unit-tests
evgueniazet Sep 18, 2023
296a981
Merge pull request #52 from evgueniazet/sprint-4_unit-tests
evgueniazet Sep 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions e-commerce-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions e-commerce-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
"@mui/material": "^5.14.4",
"@reduxjs/toolkit": "^1.9.5",
"classnames": "^2.3.2",
"history": "^5.3.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-error-boundary": "^4.0.11",
"react-hook-form": "^7.45.4",
"react-redux": "^8.1.2",
"react-router-dom": "^6.14.2",
"react-scripts": "5.0.1",
"react-toastify": "^9.1.3",
"typescript": "^4.9.5",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --coverage",
"test": "react-scripts test --coverage --watchAll",
"eject": "react-scripts eject",
"lint": "eslint src/**/*.{js,jsx,ts,tsx}",
"lint:fix": "eslint --fix src/**/*.{js,jsx,ts,tsx}",
Expand All @@ -37,6 +40,12 @@
"react-app/jest"
]
},
"jest": {
"collectCoverageFrom": [
"src/**/*.{js,jsx,ts,tsx}",
"!src/**/*.test.{js,jsx,ts,tsx}"
]
},
"browserslist": {
"production": [
">0.2%",
Expand All @@ -50,7 +59,6 @@
]
},
"devDependencies": {
"sass": "^1.66.1",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
Expand All @@ -59,10 +67,13 @@
"@types/react": "^18.2.18",
"@types/react-dom": "^18.2.7",
"@types/react-router-dom": "^5.3.3",
"@types/redux-mock-store": "^1.0.3",
"eslint": "^8.46.0",
"eslint-config-prettier": "^8.9.0",
"eslint-plugin-prettier": "^5.0.0",
"husky": "^8.0.3",
"prettier": "^3.0.0"
"prettier": "^3.0.0",
"redux-mock-store": "^1.5.4",
"sass": "^1.66.1"
}
}
42 changes: 31 additions & 11 deletions e-commerce-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ import LoadingProgress from './components/LoadingProgress/LoadingProgress';

export const App = () => {
const [getAnonymousToken] = useGetAnonymousTokenMutation();
const { isTokenInStorage, getTokenFromStorage, delTokenFromStorage } = useLocalToken();
const {
isTokenInStorage,
getTokenFromStorage,
delTokenFromStorage,
setTokenInSessionStorage,
getTokenFromSessionStorage,
isTokenInLocalStorage,
} = useLocalToken();
const [getAccessTokenApi, { data, isSuccess, isError, isLoading }] =
useGetAccessTokenFromRefreshMutation();
const [getDetails] = useGetMyCustomerDetailsMutation();
Expand All @@ -23,9 +30,9 @@ export const App = () => {
getDetails(data.access_token).then((res) => {
if ('data' in res) {
dispatch(setAuth({ email: res.data.email }));
dispatch(setLogIn());
}
});
dispatch(setLogIn());
}
}, [isSuccess, data]);

Expand All @@ -37,21 +44,34 @@ export const App = () => {
}, [isError]);

useEffect(() => {
if (accessToken) return;
if (accessToken) {
return;
}

if (isTokenInLocalStorage()) {
const token = getTokenFromSessionStorage();
if (token) {
getAccessTokenApi(token);
}
return;
}

if (isTokenInStorage()) {
const token = getTokenFromStorage();
if (token) {
getAccessTokenApi(token);
}
} else {
getAnonymousToken().then((res) => {
if ('data' in res) {
dispatch(
setAuth({ access_token: res.data.access_token, refresh_token: res.data.refresh_token }),
);
}
});
return;
}

getAnonymousToken().then((res) => {
if ('data' in res) {
dispatch(
setAuth({ access_token: res.data.access_token, refresh_token: res.data.refresh_token }),
);
setTokenInSessionStorage(res.data.refresh_token);
}
});
}, [accessToken]);

if (isLoading) {
Expand Down
92 changes: 92 additions & 0 deletions e-commerce-app/src/api/cartApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { ICartApiResponse } from '../types/slicesTypes/cart';
import { IUpdateCartApiObjectRequest } from '../types/slicesTypes/cart/updateCartApiTypes';
import { RootStateType } from '../store/store';

export const cartApi = createApi({
reducerPath: 'cartApi',
baseQuery: fetchBaseQuery({
baseUrl: `${process.env.REACT_APP_CTP_API_URL}/${process.env.REACT_APP_CTP_PROJECT_KEY}`,
}),
tagTypes: ['activeCart'],
endpoints: (build) => ({
getMyActiveCart: build.query<ICartApiResponse, string>({
query(token: string) {
return {
url: '/me/active-cart',
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
},
};
},
providesTags: ['activeCart'],
async onQueryStarted(token, { queryFulfilled, dispatch }) {
try {
queryFulfilled.catch(() => dispatch(cartApi.endpoints.createCart.initiate(token)));
} catch (e) {
dispatch(cartApi.endpoints.createCart.initiate(token));
}
},
}),
createCart: build.mutation<ICartApiResponse, string>({
query(token: string) {
return {
url: '/me/carts',
method: 'POST',
headers: {
Authorization: `Bearer ${token}`,
'Content-Type': 'application/json',
},
body: {
currency: 'EUR',
},
};
},
invalidatesTags: ['activeCart'],
}),
updateCart: build.mutation({
query(queryObj: IUpdateCartApiObjectRequest) {
return {
url: `/me/carts/${queryObj.cartId}`,
method: 'POST',
headers: {
Authorization: `Bearer ${queryObj.token}`,
'Content-Type': 'application/json',
},
body: queryObj.data,
};
},
invalidatesTags: ['activeCart'],
}),
deleteCart: build.mutation({
query(queryObj: { cartId: string; token: string }) {
return {
url: `/me/carts/${queryObj.cartId}`,
method: 'DELETE',
headers: {
Authorization: `Bearer ${queryObj.token}`,
},
};
},
}),
}),
});

export const { useLazyGetMyActiveCartQuery, useCreateCartMutation, useUpdateCartMutation } =
cartApi;

export const selectCart = (state: RootStateType) =>
cartApi.endpoints.getMyActiveCart.select(state.user.access_token as string)(state).data;
export const findProductInCart = (state: RootStateType, productId: string) =>
cartApi.endpoints.getMyActiveCart
.select(state.user.access_token as string)(state)
.data?.lineItems.find((item) => item.productId === productId);

export const getTotalQuantityLineItemsInCart = (state: RootStateType) =>
cartApi.endpoints.getMyActiveCart.select(state.user.access_token as string)(state).data
?.totalLineItemQuantity;

export const getLineItemsInCart = (state: RootStateType) =>
cartApi.endpoints.getMyActiveCart.select(state.user.access_token as string)(state).data
?.lineItems;
25 changes: 25 additions & 0 deletions e-commerce-app/src/api/discountCodesApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { createApi } from '@reduxjs/toolkit/query/react';
import { fetchBaseQuery } from '@reduxjs/toolkit/dist/query/react';
import { IGetDiscountCodesResponse } from '../types/slicesTypes/DiscountCodesTypes/DiscountCodesApiTypes';

export const discountCodesApi = createApi({
reducerPath: 'discountCodesApi',
baseQuery: fetchBaseQuery({
baseUrl: `${process.env.REACT_APP_CTP_API_URL}/${process.env.REACT_APP_CTP_PROJECT_KEY}/discount-codes`,
}),
endpoints: (build) => ({
getDiscountCodes: build.query<IGetDiscountCodesResponse, string>({
query(token) {
return {
url: '',
method: 'GET',
headers: {
Authorization: `Bearer ${token}`,
},
};
},
}),
}),
});

export const { useGetDiscountCodesQuery, useLazyGetDiscountCodesQuery } = discountCodesApi;
Loading