diff --git a/apps/dashboard/package.json b/apps/dashboard/package.json index d42751b093..725519b49f 100644 --- a/apps/dashboard/package.json +++ b/apps/dashboard/package.json @@ -45,7 +45,7 @@ "devDependencies": { "@midday/tsconfig": "workspace:*", "@t3-oss/env-nextjs": "^0.7.1", - "@types/node": "^20.10.2", + "@types/node": "^20.10.3", "@types/react": "^18.2.41", "@types/react-dom": "^18.2.17", "typescript": "^5.3.2" diff --git a/apps/dashboard/src/app/[locale]/layout.tsx b/apps/dashboard/src/app/[locale]/layout.tsx index b32dee6b61..72bbe826d1 100644 --- a/apps/dashboard/src/app/[locale]/layout.tsx +++ b/apps/dashboard/src/app/[locale]/layout.tsx @@ -4,7 +4,6 @@ import { Provider } from "./provider"; export default async function Layout({ dashboard, login, - params: { locale }, }: { dashboard: React.ReactNode; diff --git a/apps/dashboard/src/app/api/auth/callback/route.ts b/apps/dashboard/src/app/api/auth/callback/route.ts index e8363e10ca..2253a80ecc 100644 --- a/apps/dashboard/src/app/api/auth/callback/route.ts +++ b/apps/dashboard/src/app/api/auth/callback/route.ts @@ -13,6 +13,7 @@ export async function GET(req: NextRequest) { const code = requestUrl.searchParams.get("code"); const returnTo = requestUrl.searchParams.get("return_to"); const provider = requestUrl.searchParams.get("provider"); + const onboardingVisited = cookieStore.get(Cookies.OnboardingVisited)?.value; if (provider) { cookieStore.set(Cookies.PrefferedSignInProvider, provider); @@ -23,6 +24,11 @@ export async function GET(req: NextRequest) { await supabase.auth.exchangeCodeForSession(code); } + if (!onboardingVisited) { + cookieStore.set(Cookies.OnboardingVisited, "true"); + return NextResponse.redirect(`${requestUrl.origin}/onboarding`); + } + if (returnTo) { return NextResponse.redirect(`${requestUrl.origin}/${returnTo}`); } diff --git a/apps/dashboard/src/app/api/download/zip/route.ts b/apps/dashboard/src/app/api/download/zip/route.ts index e95bb1335c..e69fb45b20 100644 --- a/apps/dashboard/src/app/api/download/zip/route.ts +++ b/apps/dashboard/src/app/api/download/zip/route.ts @@ -1,19 +1,33 @@ +import { getUser } from "@midday/supabase/cached-queries"; +import { getVaultRecursiveQuery } from "@midday/supabase/queries"; import { createClient } from "@midday/supabase/server"; +import { download } from "@midday/supabase/storage"; import { BlobReader, BlobWriter, ZipWriter } from "@zip.js/zip.js"; export const preferredRegion = "fra1"; export const runtime = "edge"; +export const dynamic = "force-dynamic"; export async function GET(req, res) { - const promises = []; - const supabase = createClient(); const requestUrl = new URL(req.url); + const supabase = createClient(); + const user = await getUser(); const path = requestUrl.searchParams.get("path"); const filename = requestUrl.searchParams.get("filename"); + const promises: any = []; + + const files = await getVaultRecursiveQuery(supabase, { + teamId: user.data.team_id, + path, + }); + files.forEach((file) => { promises.push( - supabaseClient.storage.from(bucket).download(`${folder}/${file.name}`) + download(supabase, { + bucket: "vault", + path: `${file.basePath}/${file.name}`, + }) ); }); @@ -32,20 +46,21 @@ export async function GET(req, res) { }); downloadedFiles.forEach((downloadedFile) => { - if (downloadedFile) { + if (downloadedFile?.blob) { zipWriter.add(downloadedFile.name, new BlobReader(downloadedFile.blob)); } }); - // const { data } = await supabase.storage.from("vault").download(path); - // const responseHeaders = new Headers(res.headers); + const responseHeaders = new Headers(res.headers); + + responseHeaders.set( + "Content-Disposition", + `attachment; filename="${filename}.zip"` + ); - // responseHeaders.set( - // "Content-Disposition", - // `attachment; filename="${filename}"` - // ); + const data = await zipWriter.close(); - // return new Response(data, { - // headers: responseHeaders, - // }); + return new Response(data, { + headers: responseHeaders, + }); } diff --git a/apps/dashboard/src/app/layout.tsx b/apps/dashboard/src/app/layout.tsx index b48e4a5c2b..82c071bc00 100644 --- a/apps/dashboard/src/app/layout.tsx +++ b/apps/dashboard/src/app/layout.tsx @@ -26,9 +26,15 @@ export const metadata: Metadata = { ], }; -export default function Layout({ children }: { children: ReactElement }) { +export default function Layout({ + children, + params, +}: { + children: ReactElement; + params: { locale: string }; +}) { return ( - +