Skip to content

Commit

Permalink
fix creating admin notification even if product was not added
Browse files Browse the repository at this point in the history
  • Loading branch information
radekm2000 committed May 19, 2024
1 parent 9a3e31a commit 7315627
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
4 changes: 1 addition & 3 deletions client/ecommerce/src/api/responseError.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ export const ResponseErrorInterceptor = (axios: AxiosInstance) => {
if (!error.response) {
return Promise.reject(error);
}

const parseResult = z
.object({ message: z.string().optional() })
.safeParse(error.response.data);
const message = parseResult.success ? parseResult.data.message : undefined;

if (400 <= error.response.status && error.response.status < 500) {
const responseData = error.response.data as unknown;
const responseData = error.response.data as unknown
if (isValidationError(responseData)) {
return Promise.reject({
...error,
Expand Down
28 changes: 15 additions & 13 deletions client/ecommerce/src/components/inbox/InboxChatContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,19 +161,21 @@ export const InboxChatContent = ({
Delete
</Typography>
</Button>
<Button
onClick={() => {
setEditedMessageContent(message.content);
handleEditClick(index);
handleClose(index);
}}
startIcon={<EditOutlinedIcon sx={{ color: "black" }} />}
sx={{ textTransform: "none", p: 2 }}
>
<Typography sx={{ color: "black", fontWeight: "600" }}>
Edit
</Typography>
</Button>
{!message.imageUrl && (
<Button
onClick={() => {
setEditedMessageContent(message.content);
handleEditClick(index);
handleClose(index);
}}
startIcon={<EditOutlinedIcon sx={{ color: "black" }} />}
sx={{ textTransform: "none", p: 2 }}
>
<Typography sx={{ color: "black", fontWeight: "600" }}>
Edit
</Typography>
</Button>
)}
</Box>
</Popover>

Expand Down
15 changes: 0 additions & 15 deletions client/ecommerce/src/components/inbox/InboxSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Avatar, Badge, Box, Typography } from "@mui/material";
import AccountCircle from "@mui/icons-material/AccountCircle";
import { useLocation, useParams } from "wouter";
import {
FetchedNotifications,
Expand Down Expand Up @@ -73,10 +72,6 @@ export const InboxSidebar = ({
setLocation(`/inbox/${userId}`);
};

sortedRecipientsWithNotifications.map((s) => {
console.log(s.notifications);
console.log(s.notifications.length);
});
return (
<Box
sx={{
Expand Down Expand Up @@ -106,16 +101,6 @@ export const InboxSidebar = ({
},
}}
>
{/* {!recipientsOfSidebarConversation.avatar ? (
<AccountCircle
sx={{ width: "48px", height: "48px", color: "grey" }}
/>
) : (
<Avatar
sx={{ marginRight: "5px" }}
src={`${recipientsOfSidebarConversation.avatar}`}
/>
)} */}
<RenderAvatar
width="48px"
height="48px"
Expand Down
32 changes: 23 additions & 9 deletions client/ecommerce/src/components/pages/AddProduct.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
} from "@mui/material";
import AddIcon from "@mui/icons-material/Add";
import { useMediaQuery } from "../../hooks/useMediaQuery";
import { ChangeEvent, useState } from "react";
import { addProduct } from "../../api/axios";
import { ChangeEvent, useEffect, useState } from "react";
import { addProduct } from "../../api/axios";
import { useMutation } from "@tanstack/react-query";
import toast from "react-hot-toast";
import { Redirect } from "wouter";
Expand Down Expand Up @@ -90,6 +90,21 @@ export const AddProduct = () => {
photoError: false,
});

useEffect(() => {
if (success) {
mutateAdminNotification({
username: user.username,
action: `added new product ${formData.title} for ${formData.price} USD `,
createdAt: "",
});
}

return () => {
setSuccess(false);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [success]);

const handleFormChange = (
e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
) => {
Expand Down Expand Up @@ -134,11 +149,11 @@ export const AddProduct = () => {
formDataToBackend.append("data", JSON.stringify(formData));

mutate(formDataToBackend);
mutateAdminNotification({
username: user.username,
action: `added new product ${formData.title} for ${formData.price} USD `,
createdAt: "",
});
// mutateAdminNotification({
// username: user.username,
// action: `added new product ${formData.title} for ${formData.price} USD `,
// createdAt: "",
// });
};
const below700 = useMediaQuery(700);
if (success) {
Expand Down Expand Up @@ -205,7 +220,7 @@ export const AddProduct = () => {
justifyContent: "center",
alignItems: "center",
minHeight: "170px",
width: '100%'
width: "100%",
}}
>
<Box sx={{ marginRight: selectedFile ? "auto" : "" }}>
Expand All @@ -227,7 +242,6 @@ export const AddProduct = () => {
fontSize: "14px",
color: "#007782",
border: "1px solid #007782",

}}
>
<Typography sx={{ fontSize: "16px" }}>
Expand Down
1 change: 1 addition & 0 deletions client/ecommerce/src/hooks/useDeleteMessageMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const useDeleteMessageMutation = (userId: number) => {
queryClient.invalidateQueries({
queryKey: [`conversations/users/${userId}`],
});
queryClient.invalidateQueries({ queryKey: ["conversations"] });
toast.success("Message deleted!");
},
onError: (err) => {
Expand Down

0 comments on commit 7315627

Please sign in to comment.