|
| 1 | +import { useMutation } from "@tanstack/react-query"; |
| 2 | +import type { AxiosError } from "axios"; |
| 3 | +import { Check, NotebookPen } from "lucide-react"; |
| 4 | +import { useState } from "react"; |
| 5 | +import MentorApi from "~/api-requests/mentor.requests"; |
| 6 | + |
| 7 | +import { |
| 8 | + AlertDialog, |
| 9 | + AlertDialogAction, |
| 10 | + AlertDialogCancel, |
| 11 | + AlertDialogContent, |
| 12 | + AlertDialogFooter, |
| 13 | + AlertDialogHeader, |
| 14 | + AlertDialogTitle, |
| 15 | + AlertDialogTrigger, |
| 16 | +} from "~/components/ui/alert-dialog"; |
| 17 | + |
| 18 | +import { Textarea } from "~/components/ui/textarea"; |
| 19 | +import Notification from "~/utils/notification"; |
| 20 | +type NoteProps = { |
| 21 | + note: string; |
| 22 | + teamId: string; |
| 23 | +}; |
| 24 | +export function NoteTeam({ note, teamId }: NoteProps) { |
| 25 | + const [noteValue, setNoteValue] = useState(note || ""); |
| 26 | + const noteUpdateMutation = useMutation({ |
| 27 | + mutationKey: ["update-mentor-note", teamId], |
| 28 | + mutationFn: (newNote: string) => MentorApi.updateNoteTeam(teamId, newNote), |
| 29 | + onSuccess: () => { |
| 30 | + Notification.success({ |
| 31 | + text: "Thay đổi ghi chú nhóm thành công!", |
| 32 | + }); |
| 33 | + }, |
| 34 | + onError: (error: AxiosError<{ message?: string }>) => { |
| 35 | + Notification.error({ |
| 36 | + text: error.response?.data?.message || "Thay đổi ghi chú nhóm thất bại!", |
| 37 | + }); |
| 38 | + }, |
| 39 | + }); |
| 40 | + return ( |
| 41 | + <AlertDialog> |
| 42 | + <AlertDialogTrigger asChild> |
| 43 | + <div className="relative cursor-pointer rounded-xl border-2 px-4 py-2"> |
| 44 | + <div className="flex items-center gap-1"> |
| 45 | + {note ? ( |
| 46 | + <div className="absolute -top-2 -right-2 flex h-3 w-3 items-center justify-center rounded-full bg-green-500 text-white"> |
| 47 | + <Check /> |
| 48 | + </div> |
| 49 | + ) : null} |
| 50 | + <span className="text-sm font-semibold">Ghi chú nhóm</span> |
| 51 | + <NotebookPen size={20} /> |
| 52 | + </div> |
| 53 | + </div> |
| 54 | + </AlertDialogTrigger> |
| 55 | + <AlertDialogContent> |
| 56 | + <AlertDialogHeader> |
| 57 | + <AlertDialogTitle>Ghi chú</AlertDialogTitle> |
| 58 | + |
| 59 | + <Textarea |
| 60 | + placeholder="Ghi chú ...." |
| 61 | + onChange={(e) => { |
| 62 | + setNoteValue(e.target.value); |
| 63 | + }} |
| 64 | + value={noteValue} |
| 65 | + className="min-h-[120px] text-base" |
| 66 | + /> |
| 67 | + <span className="text-sm italic"> |
| 68 | + Ghi chú này giúp CLB đánh giá hiệu quả làm việc của nhóm. Các bạn vui lòng nhận xét công tâm để |
| 69 | + CLB chọn lọc được những thành viên phù hợp nhất. |
| 70 | + </span> |
| 71 | + </AlertDialogHeader> |
| 72 | + <AlertDialogFooter> |
| 73 | + <AlertDialogCancel>Đóng</AlertDialogCancel> |
| 74 | + <AlertDialogAction |
| 75 | + className="bg-black text-white" |
| 76 | + onClick={() => noteUpdateMutation.mutate(noteValue)} |
| 77 | + > |
| 78 | + Lưu |
| 79 | + </AlertDialogAction> |
| 80 | + </AlertDialogFooter> |
| 81 | + </AlertDialogContent> |
| 82 | + </AlertDialog> |
| 83 | + ); |
| 84 | +} |
0 commit comments