diff --git a/src/ui/app/business/components/banner/index.tsx b/src/ui/app/business/components/banner/index.tsx
index 3b9da865..83c94164 100644
--- a/src/ui/app/business/components/banner/index.tsx
+++ b/src/ui/app/business/components/banner/index.tsx
@@ -22,6 +22,7 @@ export default function Banner({}: Props) {
+
{
+ router.push("/");
+ }}
/>
{isTwitterUserLoggedIn ? null : (
diff --git a/src/ui/app/influencer/profile/[id]/_services/index.tsx b/src/ui/app/influencer/profile/[id]/_services/index.tsx
index 31265398..7912622d 100644
--- a/src/ui/app/influencer/profile/[id]/_services/index.tsx
+++ b/src/ui/app/influencer/profile/[id]/_services/index.tsx
@@ -4,7 +4,8 @@ import CheckoutModal from "@/src/components/checkoutModal";
import CreateUpdateService from "@/src/components/profileComponents/createUpdateService";
import { ConfirmDelete } from "@/src/components/shared/confirmDeleteModal";
import { notification } from "@/src/components/shared/notification";
-import { useAppSelector } from "@/src/hooks/useRedux";
+import { useAppDispatch, useAppSelector } from "@/src/hooks/useRedux";
+import { addOrderItem, resetCart } from "@/src/reducers/cartSlice";
import { deleteService, getService } from "@/src/services/httpServices";
import DeleteIcon from "@mui/icons-material/Delete";
import EditIcon from "@mui/icons-material/Edit";
@@ -25,16 +26,15 @@ import Image from "next/image";
import React, { useEffect } from "react";
type ServiceProps = {
- currentUser: UserType | null;
+ currentInfluencer: UserType | null;
id: string;
};
-const Services = ({ currentUser, id }: ServiceProps) => {
+const Services = ({ currentInfluencer, id }: ServiceProps) => {
+ const dispatch = useAppDispatch();
+ const cart = useAppSelector((state) => state.cart);
const loggedInUser = useAppSelector((state) => state.user?.user);
const [type, setType] = React.useState(null);
- const [checkedOutServices, setCheckedOutServices] = React.useState<
- ServiceType[]
- >([]);
const [services, setServices] = React.useState([]);
const [pagination, setPagination] = React.useState({
total_data_count: 0,
@@ -48,6 +48,8 @@ const Services = ({ currentUser, id }: ServiceProps) => {
const [selectedService, setSelectedService] =
React.useState(null);
const [deleteLoading, setDeleteLoading] = React.useState(false);
+ const [openCheckoutModal, setOpenCheckoutModal] =
+ React.useState(false);
const getServices = async () => {
try {
@@ -109,6 +111,21 @@ const Services = ({ currentUser, id }: ServiceProps) => {
}));
};
+ const addItemToCart = (service: ServiceType) => {
+ // Check if the service is already in the cart
+ dispatch(
+ addOrderItem({
+ influencer: currentInfluencer,
+ service: service,
+ })
+ );
+ };
+
+ const closeCheckoutModal = () => {
+ dispatch(resetCart());
+ setOpenCheckoutModal(false);
+ };
+
useEffect(() => {
if (refreshPage) {
getServices();
@@ -126,6 +143,12 @@ const Services = ({ currentUser, id }: ServiceProps) => {
}
}, [openModal]);
+ useEffect(() => {
+ if (cart?.orderItems?.length > 0) {
+ setOpenCheckoutModal(true);
+ }
+ }, [cart]);
+
return (
{
)}
- {services?.map((service) => {
+ {services?.map((serviceItem) => {
// Attach the platform_price to the service object
// It will be price + price * (platform_fee / 100)
// Take care of type conversion
+ let service = { ...serviceItem };
service.platform_price = (
parseFloat(service.price.toString()) +
parseFloat(service.price.toString()) *
@@ -456,10 +480,7 @@ const Services = ({ currentUser, id }: ServiceProps) => {
fullWidth
onClick={(e) => {
e.stopPropagation();
- setCheckedOutServices((prev) => [
- ...prev,
- service,
- ]);
+ addItemToCart(service);
}}
disabled={
service.package.influencer === loggedInUser?.id
@@ -477,10 +498,7 @@ const Services = ({ currentUser, id }: ServiceProps) => {
fullWidth
onClick={(e) => {
e.stopPropagation();
- setCheckedOutServices((prev) => [
- ...prev,
- service,
- ]);
+ addItemToCart(service);
}}
disabled={
service.package.influencer === loggedInUser?.id
@@ -520,11 +538,9 @@ const Services = ({ currentUser, id }: ServiceProps) => {
serviceItem={selectedService}
/>
0}
- handleClose={() => {
- setCheckedOutServices([]);
- }}
- serviceItems={checkedOutServices}
+ open={openCheckoutModal}
+ handleClose={closeCheckoutModal}
+ currentInfluencer={currentInfluencer}
/>
);
diff --git a/src/ui/app/influencer/profile/[id]/page.tsx b/src/ui/app/influencer/profile/[id]/page.tsx
index 1a581737..7caf5a71 100644
--- a/src/ui/app/influencer/profile/[id]/page.tsx
+++ b/src/ui/app/influencer/profile/[id]/page.tsx
@@ -110,6 +110,7 @@ const ProfileLayout = ({
sx={{
backgroundImage: "url(/profileBanner.png)",
border: "1px solid #000",
+ borderTop: "none",
display: "flex",
minHeight: "200px",
width: "100%",
@@ -449,7 +450,7 @@ const ProfileLayout = ({
))}
-
+
diff --git a/src/ui/src/components/checkoutModal/index.tsx b/src/ui/src/components/checkoutModal/index.tsx
index 36fa978a..5b5c2b47 100644
--- a/src/ui/src/components/checkoutModal/index.tsx
+++ b/src/ui/src/components/checkoutModal/index.tsx
@@ -1,5 +1,7 @@
"use client";
+import { useAppDispatch, useAppSelector } from "@/src/hooks/useRedux";
+import { addOrderItem, removeOrderItem } from "@/src/reducers/cartSlice";
import {
Box,
Button,
@@ -14,48 +16,37 @@ import { useRouter } from "next/navigation";
import React, { useEffect } from "react";
type CheckoutModalProps = {
- serviceItems: ServiceType[];
open: boolean;
handleClose: () => void;
+ currentInfluencer: UserType | null;
};
const CheckoutModal = ({
- serviceItems,
open,
handleClose,
+ currentInfluencer,
}: CheckoutModalProps) => {
const router = useRouter();
- const [checkedOutServices, setCheckedOutServices] = React.useState<
- Array
- >([]);
+ const cart = useAppSelector((state) => state.cart);
+ const dispatch = useAppDispatch();
- useEffect(() => {
- if (serviceItems.length === 0) {
- setCheckedOutServices([]);
- return;
- }
- const services: ServiceCheckOutType[] = [];
- serviceItems.forEach((item) => {
- const quantity = 1;
- // If the service is already in the array, then just increase the quantity
- const index = services.findIndex(
- (service) => service.serviceItem.id === item.id
- );
- if (index !== -1) {
- services[index].quantity += 1;
- services[index].price =
- parseFloat(services[index].serviceItem?.platform_price) *
- services[index].quantity;
- return;
- }
- services.push({
- serviceItem: item,
- quantity: quantity,
- price: parseFloat(item.platform_price),
- });
- });
- setCheckedOutServices(services);
- }, [serviceItems]);
+ const removeItemFromCart = (service: ServiceType) => {
+ dispatch(
+ removeOrderItem({
+ service: service,
+ })
+ );
+ };
+
+ const addItemToCart = (service: ServiceType) => {
+ // Check if the service is already in the cart
+ dispatch(
+ addOrderItem({
+ influencer: currentInfluencer,
+ service: service,
+ })
+ );
+ };
return (
- {checkedOutServices.length === 0 && (
+ {cart?.orderItems.length === 0 && (
)}
- {checkedOutServices.map((service) => (
-
- {service.serviceItem?.package?.name}
-
- {/* A counter */}
-
-
+ {cart?.orderItems.map((orderItem) => {
+ const service = orderItem?.service;
+ const quantity = orderItem?.quantity;
+ return (
+
+ {service?.package?.name}
+
+ {/* A counter */}
- {service.quantity}
+
+
+ {quantity}
+
+
-
-
-
-
- {service.price?.toFixed(2)}{" "}
- {service.serviceItem.currency.symbol}
-
-
- ))}
+
+
+ {Number(service?.platform_price)?.toFixed(2)}{" "}
+ {service.currency.symbol}
+
+
+ );
+ })}
{/* Total */}
- {checkedOutServices
- .reduce((acc, cur) => acc + cur.price, 0)
- ?.toFixed(2)}{" "}
- {checkedOutServices[0]?.serviceItem.currency.symbol}
+ {cart?.orderTotal?.toFixed(2)}{" "}
+ {cart?.orderTotalCurrency?.symbol}
@@ -266,7 +226,6 @@ const CheckoutModal = ({