Skip to content

Conversation

@ArikLeikin
Copy link
Contributor

No description provided.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this file changed? This could affect a lot of pages in the app.

Comment on lines +59 to +63
export function useAddReview() {
return useMutation({
mutationFn: (review: CreateReviewDto) => guideClient.addReview(review),
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didnt ori already have something for this?

@JosephOri

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do have exactly the same hook at reviewHooks.ts in the very same folder

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we get rid of react hook form here? we were using it for validation

@JosephOri @roiy0987 please confirm

Comment on lines +1 to +42
"use client";

import React from "react";
import { Box, IconButton } from "@mui/material";
import ModeEditOutlineOutlinedIcon from "@mui/icons-material/ModeEditOutlineOutlined";
import DeleteOutlinedIcon from "@mui/icons-material/DeleteOutlined";
import { useDeleteGuide } from "../../hooks/guideClientHooks";
import { useParams, useRouter } from "next/navigation";

const DeleteEditButtons: React.FC = () => {
const router = useRouter();
const params = useParams();

const id = params?.id ? Number(params.id) : 0;
const deleteMutation = useDeleteGuide(id);

const handleDelete = () => {
deleteMutation.mutate();
};

const handleEdit = () => {
router.push(`/new_dashboard/guides/edit/${id}`);
};

return (
<Box
sx={{
display: "flex",
gap: 0,
}}
>
<IconButton aria-label="edit" onClick={handleEdit}>
<ModeEditOutlineOutlinedIcon />
</IconButton>
<IconButton aria-label="delete" onClick={handleDelete}>
<DeleteOutlinedIcon />
</IconButton>
</Box>
);
};

export default DeleteEditButtons;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too specific. What if I want to add more buttons? You can just call it ButtonsGroup or something else.

Also make sure to add a confirmation dialog here when the user wants to delete the guide. Because he might do so by mistake and there's no check here.

Comment on lines 12 to +25
reviews: z.array(reviewSchema).optional(),
});

export type Guide = z.infer<typeof guideSchema>;

export type CreateGuideRequest = {
title: string;
contentHTML: string;
export type UpdateGuidePayload = {
id: number;
guide: {
title: string;
contentHTML: string;
};
};

export type GuideRequestUpdate = Partial<Guide>;

export type Guide = z.infer<typeof guideSchema>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were using zod for validation.

Comment on lines +19 to +21
async addReview(review: CreateReviewDto) {
return await this.post<Review>("reviews", review);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JosephOri didnt you already create this?

Copy link
Member

@JosephOri JosephOri Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was indeed created exactly this at review.client.ts

Comment on lines +34 to +36
onError: () => {
alert("Failed to delete guide. Please try again.");
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there an alert here? We should display an alert with mui. There are lot of components that can be used to display this

Comment on lines +51 to +55
onError: (error) => {
console.log(error);

alert("Failed to update guide. Please try again.");
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use a mui toast to display the error or an alert component.

return await this.get<Guide>("guides/" + guideId);
}

async createGuide(createGuideRequest: CreateGuideRequest) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why delete create guide function?

export type CreateGuideRequest = {
title: string;
contentHTML: string;
export type UpdateGuidePayload = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete the update guide payload, we dont need it cause it can be partial type of Guide, as you did here

};
};

export type GuideRequestUpdate = Partial<Guide>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why use UpdateGuidePayload and not this const?


interface Props {
initialTitle?: string;
initialIssue?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is initial issue for? now the issue will be changed to an array of categories, better to delete all the issue logic from here, when we merge the rest of the pr's all of this logic will be redundent, and we have written existing functions to handle the issue adding.

"align",
];

const handleTitleChange = (event: ChangeEvent<HTMLInputElement>) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better use a form approach like in the create guide page

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this component is basically almost a copy of the create guide page, it is better if you will use the create guide page with different props to determine if its an edit page of create page, you can extract the code in the create guide page into a component and use it with different props
https://en.wikipedia.org/wiki/Don%27t_repeat_yourself

Comment on lines +59 to +63
export function useAddReview() {
return useMutation({
mutationFn: (review: CreateReviewDto) => guideClient.addReview(review),
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do have exactly the same hook at reviewHooks.ts in the very same folder

children?: JSX.Element;
middlecontent?: string | JSX.Element;
fullHeight?: boolean;
buttons?: JSX.Element;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if it supposed to be a react element name it with a capital letter, and give more explanatory name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants