From 159f9e9fac01bed89898f0886608bed36b327e26 Mon Sep 17 00:00:00 2001 From: Joshua Oloton Date: Tue, 27 Aug 2024 17:24:44 +0100 Subject: [PATCH] fix: correct invalid export csv url --- .../admin/(settings)/settings/organization/export.ts | 11 ++++++----- .../(settings)/settings/organization/members/page.tsx | 6 +++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/app/dashboard/(admin)/admin/(settings)/settings/organization/export.ts b/src/app/dashboard/(admin)/admin/(settings)/settings/organization/export.ts index 39ea4d7eb..3c305bdc6 100644 --- a/src/app/dashboard/(admin)/admin/(settings)/settings/organization/export.ts +++ b/src/app/dashboard/(admin)/admin/(settings)/settings/organization/export.ts @@ -1,15 +1,16 @@ import axios from "axios"; import { getApiUrl } from "~/actions/getApiUrl"; -import { useSession } from "next-auth/react"; -export const exportMembersEndpoint = async (format: string = "csv") => { +export const exportMembersEndpoint = async ( + currentOrgId: string, + format: string = "csv", +) => { const apiUrl = await getApiUrl(); - const { data: session } = useSession(); - if (!session?.currentOrgId) return; + try { const response = await axios.get( - `${apiUrl}/api/v1/organisations/${session?.currentOrgId}/users/export`, + `${apiUrl}/api/v1/organisations/${currentOrgId}/users/export`, { params: { format: format, diff --git a/src/app/dashboard/(admin)/admin/(settings)/settings/organization/members/page.tsx b/src/app/dashboard/(admin)/admin/(settings)/settings/organization/members/page.tsx index 85488d79b..45e0b81ac 100644 --- a/src/app/dashboard/(admin)/admin/(settings)/settings/organization/members/page.tsx +++ b/src/app/dashboard/(admin)/admin/(settings)/settings/organization/members/page.tsx @@ -2,6 +2,7 @@ import { AxiosResponse } from "axios"; import { EllipsisIcon } from "lucide-react"; +import { useSession } from "next-auth/react"; import Link from "next/link"; import { useState } from "react"; @@ -84,6 +85,8 @@ const Members = () => { const [text, setText] = useState("Export CSV"); const [isVisible, setIsVisible] = useState(false); + const { data: session } = useSession(); + const toggleVisibility = () => { setIsVisible(!isVisible); }; @@ -117,7 +120,8 @@ const Members = () => { setExporting(true); setText("Exporting..."); - const result = await exportMembersEndpoint(); + if (!session?.currentOrgId) return; + const result = await exportMembersEndpoint(session?.currentOrgId); if (result.success) { toast({