From 7dd9f4e2c88c8e774da4ffcf476b5898d4e566f6 Mon Sep 17 00:00:00 2001 From: Guilherme Baufaker Date: Fri, 5 Apr 2024 12:04:11 -0300 Subject: [PATCH 1/2] implemented support --- actions/createTicket.ts | 47 +++++++ components/ui/NewTicketModal.tsx | 119 ++++++++++++++++ fresh.gen.ts | 2 + islands/NewTicketModal.tsx | 9 ++ manifest.gen.ts | 224 ++++++++++++++++--------------- sdk/useUI.ts | 2 + sections/Content/Support.tsx | 76 +++++++++++ 7 files changed, 369 insertions(+), 110 deletions(-) create mode 100644 actions/createTicket.ts create mode 100644 components/ui/NewTicketModal.tsx create mode 100644 islands/NewTicketModal.tsx create mode 100644 sections/Content/Support.tsx diff --git a/actions/createTicket.ts b/actions/createTicket.ts new file mode 100644 index 0000000..038b570 --- /dev/null +++ b/actions/createTicket.ts @@ -0,0 +1,47 @@ +export interface Props { + email: string; + subject: string; + content: string; +} + +const signUpCognito = async ( + props: Props, + _req: Request, +): Promise => { + const params = { + fields: [ + { + name: "email", + value: props.email, + }, + { + name: "TICKET.subject", + value: props.subject, + }, + { + name: "TICKET.content", + value: props.content, + }, + ], + }; + try { + const response = await fetch( + `https://api.hsforms.com/submissions/v3/integration/submit/43817859/88ccb64a-bb13-4c72-ade6-1bb9e6157946`, + { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(params), + }, + ); + + const res = await response.json(); + return res; + } catch (e) { + // console.log({ e }); + return e; + } +}; + +export default signUpCognito; diff --git a/components/ui/NewTicketModal.tsx b/components/ui/NewTicketModal.tsx new file mode 100644 index 0000000..924665a --- /dev/null +++ b/components/ui/NewTicketModal.tsx @@ -0,0 +1,119 @@ +import { useUI } from "../../sdk/useUI.ts"; +import { useState } from "preact/hooks"; +import Modal from "../../components/ui/Modal.tsx"; +import { invoke } from "../../runtime.ts"; + +const ModalTicket = () => { + const { displayNewTicketModal } = useUI(); + const [email, setEmail] = useState(""); + const [content, setContent] = useState(""); + const [subject, setSubject] = useState(""); + const [submitting, setSubmitting] = useState(false); + + const handleSubmitTicket = async (e: Event) => { + e.preventDefault(); + setSubmitting(true); + try { + const r = await invoke["deco-sites/ecannadeco"].actions.createTicket({ + email, + subject, + content, + }); + + const resp = r as { inlineMessage?: string }; + + if ( + resp.inlineMessage && + resp.inlineMessage == "Obrigado por enviar o formulário." + ) { + setEmail(""); + setContent(""); + setSubject(""); + + console.log({ responseTicker: r }); + setSubmitting(false); + + alert( + "Recebemos seu ticket! Em breve, te retornaremos no email informado.", + ); + displayNewTicketModal.value = false; + } + } catch (e) { + alert("Erro ao enviar ticket. Tente mais tarde"); + setSubmitting(false); + } + }; + + return ( + displayNewTicketModal.value = false} + > +
+

+ Novo Ticket de Suporte +

+ { + setEmail(e.currentTarget.value); + }} + /> + { + setSubject(e.currentTarget.value); + }} + /> +