From cfea8988ebb79868b51f5f795365c26570775334 Mon Sep 17 00:00:00 2001 From: dextmorgn Date: Wed, 19 Feb 2025 15:49:21 +0100 Subject: [PATCH] feat: rls --- src/app/dashboard/layout.tsx | 11 ++++- src/app/dashboard/page.tsx | 2 +- .../[investigation_id]/left.tsx | 7 +++- .../[investigation_id]/page.tsx | 1 - src/components/app-sidebar.tsx | 8 +++- src/components/dashboard/new-case.tsx | 40 +++++++++++-------- src/components/dashboard/search-palette.tsx | 6 +-- src/components/investigations/graph.tsx | 10 ++--- src/components/investigations/layout.tsx | 2 +- src/components/login-form.tsx | 8 ++-- src/components/nav-user.tsx | 11 ++--- src/lib/actions/investigations.ts | 27 ++++++++++++- 12 files changed, 88 insertions(+), 45 deletions(-) diff --git a/src/app/dashboard/layout.tsx b/src/app/dashboard/layout.tsx index 57c3202..841cb94 100644 --- a/src/app/dashboard/layout.tsx +++ b/src/app/dashboard/layout.tsx @@ -1,4 +1,5 @@ import { AppSidebar } from "@/components/app-sidebar" +import { createClient } from "@/lib/supabase/server"; import { Breadcrumb, BreadcrumbItem, @@ -13,15 +14,21 @@ import { SidebarProvider, SidebarTrigger, } from "@/components/ui/sidebar" +import { redirect } from "next/navigation"; -const DashboardLayout = ({ +const DashboardLayout = async ({ children, }: { children: React.ReactNode; }) => { + const supabase = await createClient() + const { data, error: userError } = await supabase.auth.getUser() + if (userError || !data?.user) { + redirect('/login') + } return ( - +
diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx index 3c33fd8..d827642 100644 --- a/src/app/dashboard/page.tsx +++ b/src/app/dashboard/page.tsx @@ -9,7 +9,7 @@ const DashboardPage = async () => { const { investigations, error } = await getInvestigations() if (error) return
An error occured.
return ( -
+

Vos investigations

diff --git a/src/app/investigations/[investigation_id]/left.tsx b/src/app/investigations/[investigation_id]/left.tsx index fc4aa15..39c3640 100644 --- a/src/app/investigations/[investigation_id]/left.tsx +++ b/src/app/investigations/[investigation_id]/left.tsx @@ -14,6 +14,7 @@ import { AccordionTrigger, } from "@/components/ui/accordion" import { useFlowStore } from '@/components/contexts/use-flow-store'; +import { usePlatformIcons } from '@/lib/hooks/use-platform-icons'; const Left = ({ investigation_id }: { investigation_id: string }) => { @@ -21,6 +22,7 @@ const Left = ({ investigation_id }: { investigation_id: string }) => { const { emails, isLoading: isLoadingEmails, refetch: refetchEmails } = useEmails(investigation_id) const { phones, isLoading: isLoadingPhones, refetch: refetchPhones } = usePhones(investigation_id) const { socials, isLoading: isLoadingSocials, refetch: refetchSocials } = useSocials(investigation_id) + const platformsIcons = usePlatformIcons() const { currentNode, setCurrentNode } = useFlowStore() @@ -116,7 +118,10 @@ const Left = ({ investigation_id }: { investigation_id: string }) => { {socials?.map((social: any) => (

  • diff --git a/src/app/investigations/[investigation_id]/page.tsx b/src/app/investigations/[investigation_id]/page.tsx index 45b7a6b..4bcea2a 100644 --- a/src/app/investigations/[investigation_id]/page.tsx +++ b/src/app/investigations/[investigation_id]/page.tsx @@ -9,7 +9,6 @@ const DashboardPage = async ({ }) => { const { investigation_id } = await (params) const { nodes, edges } = await getInvestigationData(investigation_id) - return (
    diff --git a/src/components/app-sidebar.tsx b/src/components/app-sidebar.tsx index 94ad3a0..648a865 100644 --- a/src/components/app-sidebar.tsx +++ b/src/components/app-sidebar.tsx @@ -156,7 +156,11 @@ const data = { ], } -export function AppSidebar({ ...props }: React.ComponentProps) { +interface AppSidebarProps extends React.ComponentProps { + user: any; +} + +export function AppSidebar({ user, ...props }: AppSidebarProps) { return ( @@ -167,7 +171,7 @@ export function AppSidebar({ ...props }: React.ComponentProps) { - + diff --git a/src/components/dashboard/new-case.tsx b/src/components/dashboard/new-case.tsx index 6ee621b..0e3091c 100644 --- a/src/components/dashboard/new-case.tsx +++ b/src/components/dashboard/new-case.tsx @@ -1,7 +1,10 @@ "use client" + +import type React from "react" + import { useState } from "react" import { useRouter } from "next/navigation" -import { supabase } from "@/lib/supabase/client" +import { createNewCase } from "@/lib/actions/investigations" import { Button } from "@/components/ui/button" import { Dialog, @@ -15,25 +18,30 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigge import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Badge } from "@/components/ui/badge" +import { useFormStatus } from "react-dom" + +function SubmitButton() { + const { pending } = useFormStatus() + + return ( + + ) +} export default function NewCase({ children }: { children: React.ReactNode }) { const [open, setOpen] = useState(false) const router = useRouter() - async function handleNewCase(e: React.FormEvent) { - e.preventDefault() - const formData = new FormData(e.currentTarget) - const data = Object.fromEntries(formData) - - try { - const { data: investigation, error } = await supabase.from("investigations").insert(data).select("id").single() - - if (error) throw error - if (investigation) router.push(`/investigations/${investigation.id}`) + async function handleNewCase(formData: FormData) { + const result = await createNewCase(formData) + if (result.success) { + router.push(`/investigations/${result.id}`) setOpen(false) - } catch (error) { - console.error("Error creating new case:", error) - // Handle error (e.g., show error message to user) + } else { + console.error(result.error) + // You might want to show an error message to the user here } } @@ -61,7 +69,7 @@ export default function NewCase({ children }: { children: React.ReactNode }) { New case Create a new blank case. -
    +
    @@ -80,7 +88,7 @@ export default function NewCase({ children }: { children: React.ReactNode }) { - + diff --git a/src/components/dashboard/search-palette.tsx b/src/components/dashboard/search-palette.tsx index 65f4e95..def8a77 100644 --- a/src/components/dashboard/search-palette.tsx +++ b/src/components/dashboard/search-palette.tsx @@ -54,7 +54,7 @@ const SearchModal = ({ investigation_id }: { investigation_id: string }) => {
    Individual -
    +
    { textToHighlight={item?.full_name} /> - + { - + Search diff --git a/src/components/investigations/graph.tsx b/src/components/investigations/graph.tsx index cd4272d..1008b30 100644 --- a/src/components/investigations/graph.tsx +++ b/src/components/investigations/graph.tsx @@ -1,6 +1,5 @@ "use client" -import Dagre from '@dagrejs/dagre'; -import React, { useCallback, useEffect, useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { ReactFlow, ReactFlowProvider, @@ -26,11 +25,10 @@ import { useParams } from 'next/navigation'; import { Tooltip, TooltipContent } from '@/components/ui/tooltip'; import { Button } from '@/components/ui/button'; import { TooltipTrigger } from '@radix-ui/react-tooltip'; -import { Card } from '@/components/ui/card'; import { cn } from '@/lib/utils'; import { useInvestigationContext } from '@/components/contexts/investigation-provider'; import { useFlowStore } from '../contexts/use-flow-store'; -import CurrentNode from './current-node-card'; +// import CurrentNode from './current-node-card'; const edgeTypes = { "custom": FloatingEdge @@ -140,7 +138,7 @@ const LayoutFlow = ({ theme }: { theme: ColorMode }) => {
    - {currentNode && getNode(currentNode) && ( + {/* {currentNode && getNode(currentNode) && ( getNode(currentNode)?.type === "individual" ? // @ts-ignore : @@ -149,7 +147,7 @@ const LayoutFlow = ({ theme }: { theme: ColorMode }) => { {getNode(currentNode)?.data.label} - )} + )} */}
    diff --git a/src/components/investigations/layout.tsx b/src/components/investigations/layout.tsx index a72ba24..1678a76 100644 --- a/src/components/investigations/layout.tsx +++ b/src/components/investigations/layout.tsx @@ -30,7 +30,7 @@ const InvestigationLayout = ({ const { panelOpen, setPanelOpen } = useInvestigationContext() return ( - + {panelOpen &&
    diff --git a/src/components/login-form.tsx b/src/components/login-form.tsx index 6fdda56..21ae6d1 100644 --- a/src/components/login-form.tsx +++ b/src/components/login-form.tsx @@ -7,7 +7,7 @@ import { Input } from "./ui/input" export function LoginForm() { return ( -
    +
    Login
    @@ -15,9 +15,9 @@ export function LoginForm() { Login into your account or create a new one.
    -
    +
    -
    +