MCPcopy Create free account
hub / github.com/code100x/cms / DeleteQAForm

Function DeleteQAForm

src/components/posts/form/form-delete.tsx:21–59  ·  view source on GitHub ↗
({ questionId, answerId })

Source from the content-addressed store, hash-verified

19) => Promise<ActionState<DeleteActionData, Delete>>;
20
21const DeleteQAForm: React.FC<IVoteFormProps> = ({ questionId, answerId }) => {
22 const idForm = useId();
23 const router = useRouter();
24 const deleteAction: DeleteAction = async ({ questionId, answerId }) => {
25 if (questionId) {
26 return deleteQuestion({ questionId });
27 } else if (answerId) {
28 return deleteAnswer({ answerId });
29 }
30 throw new Error('Neither questionId nor answerId is provided');
31 };
32
33 const { execute } = useAction(deleteAction, {
34 onSuccess: (data) => {
35 toast.success(`${data.message}`);
36 if (questionId) {
37 router.push('/question');
38 }
39 },
40 onError: (error) => {
41 toast.error(error);
42 },
43 });
44
45 const hanleDeleteFunction = () => {
46 execute(questionId ? { questionId } : { answerId });
47 };
48
49 return (
50 <Button
51 id={`delete-${idForm}`}
52 onClick={hanleDeleteFunction}
53 size="icon"
54 variant="destructive"
55 >
56 <Trash2 className="size-4" />
57 </Button>
58 );
59};
60
61export default DeleteQAForm;

Callers

nothing calls this directly

Calls 1

useActionFunction · 0.90

Tested by

no test coverage detected