Skip to content
Snippets Groups Projects
Commit 332c9bcf authored by VAUCHAIR MARLINE's avatar VAUCHAIR MARLINE
Browse files

:sparkles: doValidate cart with adhesion

parent 117a2c03
Branches
1 merge request!7🔀 V1
...@@ -46,6 +46,24 @@ export async function getUsers(): Promise<User[]> { ...@@ -46,6 +46,24 @@ export async function getUsers(): Promise<User[]> {
return users; return users;
}; };
export async function setAdhesion() : Promise<number> {
// Fetch users data
await axios.post(`${BASE_URL}/api/pay_adhesion`, {
headers: {
'Content-Type': 'application/json',
},
body: {
'student_number': '12345678',
}
}).then(({ data }) => data)
.catch(error => {
console.error(error);
return 0;
});
return 1;
}
function validateSubscriptionDate(dateStr: string): boolean { function validateSubscriptionDate(dateStr: string): boolean {
const YEAR_IN_MS = 31536000000; const YEAR_IN_MS = 31536000000;
const date = Date.parse(dateStr) ?? Date.parse('01 Jan 1970 00:00:00 GMT'); const date = Date.parse(dateStr) ?? Date.parse('01 Jan 1970 00:00:00 GMT');
......
...@@ -6,6 +6,7 @@ import { XIcon } from '@heroicons/react/outline' ...@@ -6,6 +6,7 @@ import { XIcon } from '@heroicons/react/outline'
import { cartContext } from '../../cart/CartStore'; import { cartContext } from '../../cart/CartStore';
import { updateProductQuantity } from '../../cart/CartActions'; import { updateProductQuantity } from '../../cart/CartActions';
import {setAdhesion} from '../../apis/student';
const Cart = () => { const Cart = () => {
const { cartState, dispatch } = useContext(cartContext); const { cartState, dispatch } = useContext(cartContext);
...@@ -15,6 +16,25 @@ const Cart = () => { ...@@ -15,6 +16,25 @@ const Cart = () => {
return `${price.toFixed(2).replace(".", ",")} €`; return `${price.toFixed(2).replace(".", ",")} €`;
} }
function doValidate(): number {
const existingProduct = cartState.cart.find(p => p.name === "Adhésion");
if (existingProduct){
setAdhesion().then((users) => {
console.log("Envoi adhésion à STUDENT: 12345678");
}).catch((_) => {
console.log("error adhesion");
});
}
cartState.totalPrice = 0;
cartState.cart.forEach((product) => {
if (product.quantity) {
cartState.totalPrice += product.price * product.quantity;
}
});
console.log("Envoi transaction à MONEY: ", cartState);
return 1;
}
let [totalPrice, setTotalPrice] = useState(0); let [totalPrice, setTotalPrice] = useState(0);
useEffect(() => { useEffect(() => {
...@@ -164,8 +184,9 @@ const Cart = () => { ...@@ -164,8 +184,9 @@ const Cart = () => {
</div> </div>
<div className="mt-10"> <div className="mt-10">
<button <button
type="submit" onClick={() => doValidate()}
className="w-full bg-indigo-600 border border-transparent rounded-md shadow-sm py-3 px-4 text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-50 focus:ring-indigo-500" type="button"
className="w-full bg-indigo-600 border border-transparent rounded-md shadow-sm py-3 px-4 text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-50 focus:ring-indigo-500"
> >
Valider Valider
</button> </button>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment