diff --git a/src/app/(gistLayout)/[username]/[gistId]/page.tsx b/src/app/(gistLayout)/[username]/[gistId]/page.tsx index 69db3f1..7209e50 100644 --- a/src/app/(gistLayout)/[username]/[gistId]/page.tsx +++ b/src/app/(gistLayout)/[username]/[gistId]/page.tsx @@ -1,10 +1,11 @@ "use client" import React from "react" import MyGistIdPage from "./page-ui" -import { useEditGist, useGist, usePatchGistContent, usePatchGistName } from "@/lib/queries/gists.queries" +import { useDeleteGist, useEditGist, useGist, usePatchGistContent, usePatchGistName } from "@/lib/queries/gists.queries" import { useToast } from "@/components/shadcn/use-toast" import { getRawGistURL } from "@/lib/utils" import { useMe } from "@/lib/queries/user.queries" +import { redirect, useRouter } from "next/navigation" interface MyGistIdFeaturePageProps { params: { @@ -15,6 +16,7 @@ interface MyGistIdFeaturePageProps { export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps) { const { gistId } = params const { data } = useGist(gistId) + const router = useRouter() const { toast } = useToast() const { data: user } = useMe() @@ -46,7 +48,6 @@ export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps }) } const onSave = (name: string, code: string) => { - console.log("save") edit({ id: gistId, name, @@ -59,8 +60,18 @@ export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps }) } - const onDelete = (id: string) => { - console.log(`Deleting gist with ID: ${id}`) + const { mutate: deleteGist } = useDeleteGist({ + onSuccess: () => { + toast({ + title: "Gist Deleted", + description: "Your gist has been deleted successfully", + }) + router.push(`/${user?.name}`) + }, + }) + + const handleDeleteGist = (id: string) => { + deleteGist(id) } const onShare = () => { @@ -100,7 +111,7 @@ export default function MyGistIdFeaturePage({ params }: MyGistIdFeaturePageProps gist={data} onDownload={onDownload} onSave={onSave} - onDelete={onDelete} + onDelete={handleDeleteGist} onShare={onShare} onCopy={onCopy} onCopyCurl={onCopyCurl} diff --git a/src/app/(gistLayout)/layout-ui.tsx b/src/app/(gistLayout)/layout-ui.tsx index 1cba26b..add5a3e 100644 --- a/src/app/(gistLayout)/layout-ui.tsx +++ b/src/app/(gistLayout)/layout-ui.tsx @@ -219,6 +219,7 @@ function CreateGistModal({ onClick={() => { onCreateGist(gistName, gistContent) setGistName("") + setGistContent("") setIsGistModalOpen(false) }} > diff --git a/src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx b/src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx index 13d9b0d..14a6e25 100644 --- a/src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx +++ b/src/app/(gistLayout)/org/[orgId]/gist/[gistId]/page.tsx @@ -1,7 +1,7 @@ "use client" import { useToast } from "@/components/shadcn/use-toast" import GistDetails from "@/components/ui/gist-details" -import { useEditGist, useGist, usePatchGistContent, usePatchGistName } from "@/lib/queries/gists.queries" +import { useDeleteGist, useEditGist, useGist, usePatchGistContent, usePatchGistName } from "@/lib/queries/gists.queries" import { useOrg } from "@/lib/queries/orgs.queries" import { useMe } from "@/lib/queries/user.queries" import { getRawGistURL } from "@/lib/utils" @@ -66,11 +66,17 @@ export default function MyOrgGistIdFeaturePage({ params }: MyOrgGistIdFeaturePag }) } - const onDelete = (id: string) => { - toast({ - title: "Gist Deleted", - description: "Your gist has been deleted successfully", - }) + const { mutate: deleteGist } = useDeleteGist({ + onSuccess: () => { + toast({ + title: "Gist Deleted", + description: "Your gist has been deleted successfully", + }) + }, + }) + + const handleDeleteGist = (id: string) => { + deleteGist(id) } const onCopy = (code: string) => { @@ -109,7 +115,7 @@ export default function MyOrgGistIdFeaturePage({ params }: MyOrgGistIdFeaturePag onDownload={onDownload} onSave={onSave} onShare={onShare} - onDelete={onDelete} + onDelete={handleDeleteGist} onCopy={onCopy} onCopyCurl={onCopyCurl} /> diff --git a/src/components/logic/mygist-list-logic.tsx b/src/components/logic/mygist-list-logic.tsx index ceff86d..d671825 100644 --- a/src/components/logic/mygist-list-logic.tsx +++ b/src/components/logic/mygist-list-logic.tsx @@ -5,6 +5,7 @@ import MyGistList from "../ui/mygist-list" import { useDeleteGist, useGists } from "@/lib/queries/gists.queries" import { PaginationContext } from "../contexts/pagination" import { useMe } from "@/lib/queries/user.queries" +import { toast } from "../shadcn/use-toast" export function MyGistListFeature() { const { data: user } = useMe() @@ -19,8 +20,11 @@ export function MyGistListFeature() { }, [nb_pages, setNbPages]) const { mutate: deleteGist } = useDeleteGist({ - onSuccess: (id) => { - console.log(`Deleting gist with ID: ${id}`) + onSuccess: () => { + toast({ + title: "Gist Deleted", + description: "Your gist has been deleted successfully", + }) }, }) diff --git a/src/components/logic/org-list-logic.tsx b/src/components/logic/org-list-logic.tsx index 98ac730..6df6820 100644 --- a/src/components/logic/org-list-logic.tsx +++ b/src/components/logic/org-list-logic.tsx @@ -1,20 +1,38 @@ +import { useDeleteGist } from "@/lib/queries/gists.queries" import { OrgList } from "../ui/org-list" import { useDeleteOrgs, useOrgs } from "@/lib/queries/orgs.queries" +import { toast } from "../shadcn/use-toast" export function OrgListFeature() { const { data } = useOrgs() - const { mutate } = useDeleteOrgs({ onSuccess: () => console.log("Deleted") }) + const { mutate: deleteOrg } = useDeleteOrgs({ + onSuccess: () => { + toast({ + title: "Orgnization Deleted", + description: "Your organization has been deleted successfully", + }) + }, + }) - const onDeleteTeam = (id: string) => { - mutate(id) + const handleDeleteOrg = (id: string) => { + deleteOrg(id) } const onGistOrg = () => { console.log("Gist Org Clicked") } - const onDeleteGist = (id: string) => { - console.log(`Deleting gist with ID: ${id}`) + const { mutate: deleteGist } = useDeleteGist({ + onSuccess: () => { + toast({ + title: "Gist Deleted", + description: "Your gist has been deleted successfully", + }) + }, + }) + + const handleDeleteGist = (id: string) => { + deleteGist(id) } const onUpdateOrg = (id: string, name: string) => { @@ -25,8 +43,8 @@ export function OrgListFeature() { )