Skip to content

Commit

Permalink
#93
Browse files Browse the repository at this point in the history
  • Loading branch information
fdhhhdjd committed Oct 25, 2022
1 parent 8aa7a75 commit b329dce
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 0 deletions.
Binary file modified dump.rdb
Binary file not shown.
5 changes: 5 additions & 0 deletions frontend/src/v1/configs/Apis/Payment_Api/Api_Payment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const API_PAYMENT = {
//* TOTAL PAYMENT
API_TOTAL_PAYMENT: "/api/payment/total",
};
export default API_PAYMENT;
26 changes: 26 additions & 0 deletions frontend/src/v1/redux/payment_slice/Api_Redux_Thunk_Payment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { createAsyncThunk } from "@reduxjs/toolkit";
import axios from "axios";
import API_PAYMENT from "../../configs/Apis/Payment_Api/Api_Payment";

export const Get_Detail_User_Payment_Initial = createAsyncThunk(
"Payment/User",
async (accessToken, { rejectWithValue }) => {
const config = {
headers: {
Authorization: `Bearer ${accessToken}`,
},
};
try {
const response = await axios.get(
`${API_PAYMENT.API_TOTAL_PAYMENT}`,
config
);
return response.data;
} catch (error) {
if (!error.response) {
throw error;
}
return rejectWithValue(error.response.data);
}
}
);
33 changes: 33 additions & 0 deletions frontend/src/v1/redux/payment_slice/payment_slice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createSlice } from "@reduxjs/toolkit";
import { Get_Detail_User_Payment_Initial } from "./Api_Redux_Thunk_Payment";
const initialState = {
loading: false,
error: null,
total_user: 0,
};
const Payments = createSlice({
name: "payments",
initialState,
reducers: {
reset_total: (state) => {
state.total_user = 0;
},
},
extraReducers: {
//* Payment UserId
[Get_Detail_User_Payment_Initial.pending]: (state, action) => {
state.loading = true;
},
[Get_Detail_User_Payment_Initial.fulfilled]: (state, action) => {
state.loading = false;
state.total_user = action.payload.element;
},
[Get_Detail_User_Payment_Initial.rejected]: (state, action) => {
state.loading = false;
state.error = action.payload;
},
},
});
const Payment_Slice = Payments.reducer;
export const { reset_total } = Payments.actions;
export default Payment_Slice;
2 changes: 2 additions & 0 deletions frontend/src/v1/redux/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Comment_Slice from "./comment_Slice/Comment_Slice";
import Products_Slice from "./product_slice/Product_Slice";
import Upload_Cloud_Slice from "./upload_Slice/Upload_Slice";
import Cart_Slice from "./cart_slice/Cart_Slice";
import Payment_Slice from "./payment_slice/payment_slice";
const rootReducer = (state, action) => {
return AuthenticationSlice(state, action);
};
Expand All @@ -18,6 +19,7 @@ store = configureStore({
Products_user: Products_Slice,
Comment_product: Comment_Slice,
Cart_user: Cart_Slice,
payment_user: Payment_Slice,
reducer: rootReducer,
},

Expand Down
2 changes: 2 additions & 0 deletions frontend/src/v1/user_ui/contexts/GlobalStateUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import UserApi from "./Auth_Users_Context/Auth_Users";
import ProductApi from "./Product_Context/Product_Context";
import CarouselApi from "./Carousel_Context/Carousel_Context";
import Cart_Context from "./Cart_Context/Cart_Context";
import PaymentApi from "./Payment_Context/Payment_Context";
export const API_USER = `${CONFIGS.REACT_APP_API_URL}/api/user`;
export const StoreContextUser = createContext();
export const useContextUser = () => useContext(StoreContextUser);
Expand Down Expand Up @@ -42,6 +43,7 @@ export const DataProviderUser = ({ children }) => {
Product_Api_Context: ProductApi(),
Cart_Context: Cart_Context(),
Carousel_Api_Context: CarouselApi(),
Payment_Api_Context: PaymentApi(),
};
StoreContextUser.displayName = "Global State User";
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useEffect } from "react";
import { useDispatch, useSelector } from "react-redux";
import { Get_Detail_User_Payment_Initial } from "../../../redux/payment_slice/Api_Redux_Thunk_Payment";

const Payment_Context = () => {
const { accessToken } = useSelector((state) => ({
...state.auth_user,
}));
const { change_cart } = useSelector((state) => ({
...state.Cart_user,
}));
const dispatch = useDispatch();
useEffect(() => {
if (accessToken || change_cart) {
dispatch(Get_Detail_User_Payment_Initial(accessToken));
}
}, [accessToken, change_cart]);
return {};
};
export default Payment_Context;

0 comments on commit b329dce

Please sign in to comment.