-
Notifications
You must be signed in to change notification settings - Fork 0
added changes for edit and delete guides #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
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.
| export function useAddReview() { | ||
| return useMutation({ | ||
| mutationFn: (review: CreateReviewDto) => guideClient.addReview(review), | ||
| }); | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
| "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; |
There was a problem hiding this comment.
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.
| 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>; |
There was a problem hiding this comment.
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.
| async addReview(review: CreateReviewDto) { | ||
| return await this.post<Review>("reviews", review); | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
| onError: () => { | ||
| alert("Failed to delete guide. Please try again."); | ||
| }, |
There was a problem hiding this comment.
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
| onError: (error) => { | ||
| console.log(error); | ||
|
|
||
| alert("Failed to update guide. Please try again."); | ||
| }, |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 = { |
There was a problem hiding this comment.
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>; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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>) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
| export function useAddReview() { | ||
| return useMutation({ | ||
| mutationFn: (review: CreateReviewDto) => guideClient.addReview(review), | ||
| }); | ||
| } |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
No description provided.