From 571cbdff47d6fbd7c01aa4f3f6a9bde35f6d691c Mon Sep 17 00:00:00 2001 From: Akmal Isomadinov Date: Thu, 18 Jul 2024 19:07:45 +0500 Subject: [PATCH] Doceditor:Utils:Action Added getFillingSession --- .../src/app/(root)/completed-form/page.tsx | 7 ++++- packages/doceditor/src/utils/actions.ts | 28 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/doceditor/src/app/(root)/completed-form/page.tsx b/packages/doceditor/src/app/(root)/completed-form/page.tsx index a853ea91e4..cbac741581 100644 --- a/packages/doceditor/src/app/(root)/completed-form/page.tsx +++ b/packages/doceditor/src/app/(root)/completed-form/page.tsx @@ -24,6 +24,7 @@ // content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 // International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode import { CompletedForm } from "@/components/completed-form"; +import { getFillingSession } from "@/utils/actions"; interface PageProps { searchParams: Record; @@ -32,7 +33,11 @@ interface PageProps { async function Page({ searchParams }: PageProps) { const { share, fileId, fillingSessionId } = searchParams; - console.log({ share, fileId, fillingSessionId }); + console.log({ fillingSessionId, fileId, share }); + + const session = await getFillingSession(fillingSessionId!, share); + + console.log({ session }); return ; } diff --git a/packages/doceditor/src/utils/actions.ts b/packages/doceditor/src/utils/actions.ts index 6733c542ab..4497a1f552 100644 --- a/packages/doceditor/src/utils/actions.ts +++ b/packages/doceditor/src/utils/actions.ts @@ -48,6 +48,34 @@ import type { import { REPLACED_URL_PATH } from "./constants"; +export async function getFillingSession( + fillingSessionId: string, + share?: string, +) { + const [request] = createRequest( + [`/files/file/fillresult?fillingSessionId=${fillingSessionId}`], + [ + ["Content-Type", "application/json;charset=utf-8"], + share ? ["Request-Token", share] : ["", ""], + ], + "GET", + ); + + try { + console.log({ request }); + + const response = await fetch(request); + + if (response.ok) return await response.json(); + + throw new Error("Something went wrong", { + cause: await response.json(), + }); + } catch (error) { + console.log("File copyas error ", error); + } +} + export async function fileCopyAs( fileId: string, destTitle: string,