From e19f8b7556bb48f373be11bc6d65e66d6b6d0dc2 Mon Sep 17 00:00:00 2001 From: Guilherme Baufaker Date: Tue, 14 May 2024 09:27:41 -0300 Subject: [PATCH] integrated bulkcreateusers in association admin --- components/ui/AssociationAdmin.tsx | 5 +++- components/ui/PreSignupUsersModal.tsx | 41 +++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/components/ui/AssociationAdmin.tsx b/components/ui/AssociationAdmin.tsx index 04eff24..daaf437 100644 --- a/components/ui/AssociationAdmin.tsx +++ b/components/ui/AssociationAdmin.tsx @@ -512,7 +512,10 @@ function MyAccount() { console.log("on finish")} + onFinish={() => { + displayPreSignupUsersModal.value = false; + handleGetUsers(1); + }} /> {isLoadingUsers diff --git a/components/ui/PreSignupUsersModal.tsx b/components/ui/PreSignupUsersModal.tsx index 3009c20..bfd4725 100644 --- a/components/ui/PreSignupUsersModal.tsx +++ b/components/ui/PreSignupUsersModal.tsx @@ -3,6 +3,8 @@ import Icon from "../../components/ui/Icon.tsx"; import { useState } from "preact/hooks"; import { useUI } from "../../sdk/useUI.ts"; import { h } from "preact"; +import { IS_BROWSER } from "$fresh/runtime.ts"; +import { invoke } from "../../runtime.ts"; export interface Props { onFinish: () => void; @@ -22,14 +24,41 @@ const PreSignupUsersModal = ({ onFinish }: Props) => { } }; - const handleCreate = () => { + const handleCreate = async () => { + let accessToken = ""; + + if (IS_BROWSER) { + accessToken = localStorage.getItem("AccessToken") || ""; + } + setIsUploading(true); - try { - console.log("oi"); - } catch (e) { - console.log({ erroUpload: e }); - setIsUploading(false); + if (file) { + const formData = new FormData(); + formData.append("file", file); + + try { + const response = await fetch( + "https://service.ecanna.com.br/profile/", + { + method: "POST", + body: formData, + headers: { + Authorization: accessToken, + ContentType: "multipart/form-data", + }, + }, + ); + const r = await response.json(); + + console.log({ responsePresignup: r }); + setIsUploading(false); + + onFinish(); + } catch (e) { + console.log({ erroUpload: e }); + setIsUploading(false); + } } };