Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

add site deletion

Bill Yangdb60a525d92e
diff --git a/client/src/app/[site]/settings/DeleteSite.tsx b/client/src/app/[site]/settings/DeleteSite.tsx
new file mode 100644
index 000000000..51593df8f
--- /dev/null
+++ b/client/src/app/[site]/settings/DeleteSite.tsx
@@ -0,0 +1,42 @@
+import { useState } from "react";
+import { ConfirmationModal } from "../../../components/ConfirmationModal";
+import { Button } from "../../../components/ui/button";
+import {
+ APIResponse,
+ deleteSite,
+ GetSitesResponse,
+ useGetSites,
+} from "../../../hooks/api";
+import { useRouter } from "next/navigation";
+
+export function DeleteSite({
+ site,
+}: {
+ site: APIResponse<GetSitesResponse>["data"][number];
+}) {
+ const { refetch } = useGetSites();
+ const [isOpen, setIsOpen] = useState(false);
+ const router = useRouter();
+
+ return (
+ <ConfirmationModal
+ title="Delete Site"
+ description={`Are you sure you want to delete ${site.domain}? All tracking history will be deleted.`}
+ isOpen={isOpen}
+ setIsOpen={setIsOpen}
+ onConfirm={async () => {
+ await deleteSite(site.site_id);
+ refetch();
+ router.push("/");
+ }}
+ primaryAction={{
+ variant: "destructive",
+ children: "Delete",
+ }}
+ >
+ <Button variant={"destructive"} size={"sm"}>
+ Delete
+ </Button>
+ </ConfirmationModal>
+ );
+}
diff --git a/client/src/app/[site]/settings/General.tsx b/client/src/app/[site]/settings/General.tsx
new file mode 100644
index 000000000..7482457a8
--- /dev/null
+++ b/client/src/app/[site]/settings/General.tsx
@@ -0,0 +1,54 @@
+import { useState } from "react";
+import { Button } from "../../../components/ui/button";
+import {
+ Card,
+ CardContent,
+ CardFooter,
+ CardHeader,
+ CardTitle,
+} from "../../../components/ui/card";
+import { Input } from "../../../components/ui/input";
+import { Label } from "../../../components/ui/label";
+import { APIResponse, GetSitesResponse } from "../../../hooks/api";
+import { DeleteSite } from "./DeleteSite";
+
+export function General({
+ site,
+}: {
+ site: APIResponse<GetSitesResponse>["data"][number];
+}) {
+ const [domain, setDomain] = useState("");
+
+ const hasChanges = domain !== site.domain;
+
+ return (
+ <div className="flex flex-col gap-4">
+ <Card className="p-2">
+ <CardHeader>
+ <CardTitle className="text-xl">General</CardTitle>
+ </CardHeader>
+ <CardContent className="flex flex-col gap-4">
+ <div className="grid w-full items-center gap-1.5">
+ <Label htmlFor="domain">Username</Label>
+ <Input
+ className="w-60"
+ id="domain"
+ value={domain}
+ onChange={({ target }) => setDomain(target.value)}
+ />
+ </div>
+ </CardContent>
+ <CardFooter className="flex justify-end">
+ <Button variant={"accent"} disabled={!hasChanges}>
+ Save Changes
+ </Button>
+ </CardFooter>
+ </Card>
+ <Card className="p-2 pt-6">
+ <CardContent className="flex flex-col gap-4">
+ <DeleteSite site={site} />
+ </CardContent>
+ </Card>
+ </div>
+ );
+}
diff --git a/client/src/app/[site]/settings/page.tsx b/client/src/app/[site]/settings/page.tsx
new file mode 100644
index 000000000..75401bbc7
--- /dev/null
+++ b/client/src/app/[site]/settings/page.tsx
@@ -0,0 +1,43 @@
+"use client";
+
+import { Button } from "@/components/ui/button";
+import { GearSix } from "@phosphor-icons/react";
+import { usePathname } from "next/navigation";
+import { useState } from "react";
+import { useGetSites } from "../../../hooks/api";
+import { General } from "./General";
+
+export default function SettingsPage() {
+ const [selectedTab, setSelectedTab] = useState<"general">("general");
+ const { data: sites } = useGetSites();
+ const pathname = usePathname();
+
+ const site = sites?.data?.find(
+ (site) => site.site_id === Number(pathname.split("/")[1])
+ );
+
+ return (
+ <div className="max-w-6xl">
+ <div className="flex items-center gap-2 text-xl font-bold mb-4">
+ <img
+ className="w-7 mr-1"
+ src={`https://www.google.com/s2/favicons?domain=${site?.domain}&sz=64`}
+ />
+ <div>{site?.domain}</div>
+ </div>
+ <div className="grid grid-cols-[200px_1fr] gap-6">
+ <div className="flex flex-col gap-2">
+ <Button
+ variant={selectedTab === "general" ? "default" : "ghost"}
+ onClick={() => setSelectedTab("general")}
+ className="justify-start"
+ >
+ <GearSix size={16} weight="bold" />
+ General
+ </Button>
+ </div>
+ {selectedTab === "general" && site && <General site={site} />}
+ </div>
+ </div>
+ );
+}
diff --git a/client/src/hooks/utils.ts b/client/src/hooks/utils.ts
index 0ba8d13d2..faca60b33 100644
--- a/client/src/hooks/utils.ts
+++ b/client/src/hooks/utils.ts
@@ -19,9 +19,9 @@ export function getStartAndEndDate(time: Time) {
export async function authedFetch(url: string, opts: RequestInit = {}) {
return fetch(url, {
credentials: "include",
- headers: {
- "Content-Type": "application/json",
- },
+ // headers: {
+ // "Content-Type": "application/json",
+ // },
...opts,
});
}
diff --git a/server/src/actions/sites/deleteSite.ts b/server/src/actions/sites/deleteSite.ts
index 2ef3cbc0a..799a25406 100644
--- a/server/src/actions/sites/deleteSite.ts
+++ b/server/src/actions/sites/deleteSite.ts
@@ -3,6 +3,7 @@ import { FastifyReply } from "fastify";
import { FastifyRequest } from "fastify";
import { sql } from "../../db/postgres/postgres.js";
import { loadAllowedDomains } from "../../lib/allowedDomains.js";
+import clickhouse from "../../db/clickhouse/clickhouse.js";
export async function deleteSite(
request: FastifyRequest<{ Params: { id: string } }>,
@@ -10,7 +11,10 @@ export async function deleteSite(
) {
const { id } = request.params;
- await sql`DELETE FROM sites WHERE id = ${id}`;
+ await sql`DELETE FROM sites WHERE site_id = ${id}`;
+ // await clickhouse.query({
+ // query: `DELETE FROM pageviews WHERE site_id = ${id}`,
+ // });
await loadAllowedDomains();
return reply.status(200).send();