-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
26
frontend/src/v1/redux/payment_slice/Api_Redux_Thunk_Payment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
frontend/src/v1/user_ui/contexts/Payment_Context/Payment_Context.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |