Skip to content

Commit

Permalink
Merge pull request #17 from deco-sites/feature/user-associated-signup
Browse files Browse the repository at this point in the history
implemented user associated signup
  • Loading branch information
baufaker authored Apr 10, 2024
2 parents 4c0fc94 + 8c9e73e commit 5bb3c3f
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 55 deletions.
25 changes: 25 additions & 0 deletions actions/getAssociation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export interface Props {
id: string;
}

const getAssociation = async (
{ id }: Props,
_req: Request,
): Promise<unknown | null> => {
try {
const response = await fetch(`http://localhost:3000/associations/${id}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
},
});

const res = await response.json();
return res;
} catch (e) {
// console.log({ e });
return e;
}
};

export default getAssociation;
2 changes: 0 additions & 2 deletions components/header/Drawers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ const Aside = (
function Drawers({ menu, searchbar, children, platform }: Props) {
const { displayCart, displayMenu, displaySearchDrawer, user } = useUI();

console.log({ userDrawers: user.value });

//if user is not loggedin, use the public navitems in the menu
if (localStorage.getItem("AccessToken") == "") {
menu.items = menu.publicItems || [];
Expand Down
11 changes: 9 additions & 2 deletions components/ui/ConfirmSignup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ function ConfirmSignup() {
const [sending, setSending] = useState(false);
const [codeSent, setCodeSent] = useState(false);
const [timer, setTimer] = useState(30);
const [association, setAssociation] = useState(
localStorage.getItem("associationSignup") || "",
);
const [email, setEmail] = useState(
localStorage.getItem("emailConfirm") || "",
);
Expand Down Expand Up @@ -59,10 +62,14 @@ function ConfirmSignup() {

if (data.message) {
setLoading(false);
alert(data.message);
alert(`Erro: ${data.message}`);
} else {
setLoading(false);
window.location.href = "/confirmar-cadastro/plano";
if (association != "") {
window.location.href = "/confirmar-cadastro/associacao";
} else {
window.location.href = "/confirmar-cadastro/plano";
}
}
} catch (e) {
alert(
Expand Down
1 change: 1 addition & 0 deletions components/ui/PrivatePageControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function PrivatePageControl(props: Props) {
}
} catch (error) {
console.error("Erro ao carregar dados:", error);
localStorage.setItem("AccessToken", "");
window.location.href = "/";
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/ui/PublicPageControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function PublicPageControl(props: Props) {
},
}).then((r) => r.json());

const username = response.data?.Username;
const username = response.data.Username;

if (username) {
window.location.href = props.redirectTo || "/meus-dados";
Expand Down
15 changes: 13 additions & 2 deletions components/ui/SignUpForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,14 @@ function SignUpForm({ formTitle }: Props) {
{ email, password, name, cpf },
);

const dataS = dataSignup as { errors?: Array<unknown> };
const dataS = dataSignup as {
errors?: Array<unknown>;
data?: { association?: { "_id": string } };
};

console.log({ dataS });
const association = dataS.data?.association;

console.log({ dataSignup, dataS });

if (dataS.errors && dataS.errors.length > 0) {
alert(
Expand All @@ -46,6 +51,12 @@ function SignUpForm({ formTitle }: Props) {
localStorage.setItem("emailConfirm", email);
localStorage.setItem("cpfUserAsaas", cpf);
localStorage.setItem("nameUserAsaas", name);

if (association) {
localStorage.setItem("associationSignup", association._id);
localStorage.setItem("nameUserAssociationSignup", name);
}

setLoading(false);
window.location.href = "/confirmar-cadastro";
}
Expand Down
135 changes: 135 additions & 0 deletions components/ui/UserAssociatedSignup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import FormWrap from "./FormWrap.tsx";
import { useEffect, useState } from "preact/hooks";
import Image from "apps/website/components/Image.tsx";
import Icon from "./Icon.tsx";
import { invoke } from "../../runtime.ts";
import Loading from "../../components/daisy/Loading.tsx";

export type Association = {
cnpj: string;
logo_url: string;
name: string;
};

function UserAssociatedSignup() {
const [loading, setLoading] = useState(true);
const [associationName, setAssociationName] = useState("");
const [associationLogo, setAssociationLogo] = useState("");
const [userName, setUserName] = useState(
localStorage.getItem("nameUserAssociationSignup"),
);

useEffect(() => {
setLoading(true);
try {
invoke["deco-sites/ecannadeco"].actions.getAssociation({
id: localStorage.getItem("associationSignup") || "",
}).then((r) => {
const resp = r as Association;
setAssociationName(resp.name);
setAssociationLogo(resp.logo_url);
setLoading(false);
});
} catch (e) {
alert(
"Não foi possível carregar associação. Contacte o suporte.",
);
}
}, []); // Passando um array de dependências vazio

const handleProceed = () => {
localStorage.setItem("associationSignup", "");
window.location.href = "/entrar";
}

return (
<FormWrap>
{loading
? <Loading style="loading-spinner" size="loading-md" />
: (
<div class="flex flex-col items-center gap-4">
<span class="text-2xl text-[#8b8b8b] font-semibold text-center my-4">
Bem vindo, {userName}!
</span>
<div class="flex flex-col gap-4 ietms-center">
<span>
Reconhecemos que você possui associação com a{" "}
<span class="font-bold">{associationName}</span>
</span>
<div class="flex justify-center">
<Image
src={associationLogo}
alt={"logo associação"}
width={117}
height={32}
/>
</div>
<span>
Por conta da sua associação, você tem condições especiais para
garantir sua segurança como paciente de cannabis medicinal.
</span>
</div>
<div class="flex w-full">
<ul class="flex flex-col gap-3 w-full">
<li class="flex gap-3 items-center">
<Icon
class="text-primary"
id="CircleCheck"
size={17}
/>
<span class="text-[10px]">
Uso gratuito estendido
</span>
</li>
<li class="flex gap-3 items-center">
<Icon
class="text-primary"
id="CircleCheck"
size={17}
/>
<span class="text-[10px]">
Carteirinha digital oficial
</span>
</li>
<li
class={`flex gap-3 items-center`}
>
<Icon
class="text-primary"
id="CircleCheck"
size={17}
/>
<span class="text-[10px]">
Upload ilimitado de documentos
</span>
</li>
<li
class={`flex gap-3 items-center`}
>
<Icon
class="text-primary"
id="CircleCheck"
size={17}
/>
<span class="text-[10px]">
Suporte ilimitado do uso da plataforma
</span>
</li>
</ul>
</div>
<div class="flex flex-col gap-4">
<span>
Agora que o seu cadastro está feito, basta prosseguir para o
login e acessar sua conta.
</span>
<button onClick={handleProceed} class="btn btn-primary text-white w-full mt-2">
PROSSEGUIR
</button>
</div>
</div>
)}
</FormWrap>
);
}

export default UserAssociatedSignup;
2 changes: 2 additions & 0 deletions fresh.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import * as $SignUpForm from "./islands/SignUpForm.tsx";
import * as $Signout from "./islands/Signout.tsx";
import * as $SliderJS from "./islands/SliderJS.tsx";
import * as $UserAlerts from "./islands/UserAlerts.tsx";
import * as $UserAssociatedSignup from "./islands/UserAssociatedSignup.tsx";
import * as $WishlistButton_vtex from "./islands/WishlistButton/vtex.tsx";
import * as $WishlistButton_wake from "./islands/WishlistButton/wake.tsx";
import { type Manifest } from "$fresh/server.ts";
Expand Down Expand Up @@ -88,6 +89,7 @@ const manifest = {
"./islands/Signout.tsx": $Signout,
"./islands/SliderJS.tsx": $SliderJS,
"./islands/UserAlerts.tsx": $UserAlerts,
"./islands/UserAssociatedSignup.tsx": $UserAssociatedSignup,
"./islands/WishlistButton/vtex.tsx": $WishlistButton_vtex,
"./islands/WishlistButton/wake.tsx": $WishlistButton_wake,
},
Expand Down
7 changes: 7 additions & 0 deletions islands/UserAssociatedSignup.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Component from "deco-sites/ecannadeco/components/ui/UserAssociatedSignup.tsx";

function Island() {
return <Component />;
}

export default Island;
101 changes: 53 additions & 48 deletions manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ import * as $$$$$$$$$5 from "./actions/confirmForgotPassword.ts";
import * as $$$$$$$$$6 from "./actions/createTicket.ts";
import * as $$$$$$$$$7 from "./actions/deleteDocument.ts";
import * as $$$$$$$$$8 from "./actions/forgotPassword.ts";
import * as $$$$$$$$$9 from "./actions/getCids.ts";
import * as $$$$$$$$$10 from "./actions/getDocs.ts";
import * as $$$$$$$$$11 from "./actions/getPlans.ts";
import * as $$$$$$$$$12 from "./actions/getProfile.ts";
import * as $$$$$$$$$13 from "./actions/getUser.ts";
import * as $$$$$$$$$14 from "./actions/resendConfirmationCode.ts";
import * as $$$$$$$$$15 from "./actions/updateProfile.ts";
import * as $$$$$$$$$16 from "./actions/updateUserData.ts";
import * as $$$$$$$$$17 from "./actions/uploadFile.ts";
import * as $$$$$$$$$9 from "./actions/getAssociation.ts";
import * as $$$$$$$$$10 from "./actions/getCids.ts";
import * as $$$$$$$$$11 from "./actions/getDocs.ts";
import * as $$$$$$$$$12 from "./actions/getPlans.ts";
import * as $$$$$$$$$13 from "./actions/getProfile.ts";
import * as $$$$$$$$$14 from "./actions/getUser.ts";
import * as $$$$$$$$$15 from "./actions/resendConfirmationCode.ts";
import * as $$$$$$$$$16 from "./actions/updateProfile.ts";
import * as $$$$$$$$$17 from "./actions/updateUserData.ts";
import * as $$$$$$$$$18 from "./actions/uploadFile.ts";
import * as $$$$$$$$$$$0 from "./apps/decohub.ts";
import * as $$$$$$$$$$$1 from "./apps/site.ts";
import * as $$$2 from "./loaders/availableIcons.ts";
Expand Down Expand Up @@ -83,21 +84,22 @@ import * as $$$$$$53 from "./sections/Miscellaneous/Signout.tsx";
import * as $$$$$$52 from "./sections/Miscellaneous/SignUp.tsx";
import * as $$$$$$54 from "./sections/Miscellaneous/Slide.tsx";
import * as $$$$$$55 from "./sections/Miscellaneous/UserAlerts.tsx";
import * as $$$$$$56 from "./sections/Newsletter/Newsletter.tsx";
import * as $$$$$$57 from "./sections/Product/ImageGalleryFrontBack.tsx";
import * as $$$$$$58 from "./sections/Product/ImageGallerySlider.tsx";
import * as $$$$$$59 from "./sections/Product/NotFound.tsx";
import * as $$$$$$60 from "./sections/Product/NotFoundChallenge.tsx";
import * as $$$$$$61 from "./sections/Product/ProductDetails.tsx";
import * as $$$$$$62 from "./sections/Product/ProductInfo.tsx";
import * as $$$$$$63 from "./sections/Product/ProductShelf.tsx";
import * as $$$$$$64 from "./sections/Product/ProductShelfTabbed.tsx";
import * as $$$$$$65 from "./sections/Product/SearchResult.tsx";
import * as $$$$$$66 from "./sections/Product/ShelfWithImage.tsx";
import * as $$$$$$67 from "./sections/Product/Wishlist.tsx";
import * as $$$$$$68 from "./sections/Social/InstagramPosts.tsx";
import * as $$$$$$69 from "./sections/Social/WhatsApp.tsx";
import * as $$$$$$70 from "./sections/Theme/Theme.tsx";
import * as $$$$$$56 from "./sections/Miscellaneous/UserAssociatedSignup.tsx";
import * as $$$$$$57 from "./sections/Newsletter/Newsletter.tsx";
import * as $$$$$$58 from "./sections/Product/ImageGalleryFrontBack.tsx";
import * as $$$$$$59 from "./sections/Product/ImageGallerySlider.tsx";
import * as $$$$$$60 from "./sections/Product/NotFound.tsx";
import * as $$$$$$61 from "./sections/Product/NotFoundChallenge.tsx";
import * as $$$$$$62 from "./sections/Product/ProductDetails.tsx";
import * as $$$$$$63 from "./sections/Product/ProductInfo.tsx";
import * as $$$$$$64 from "./sections/Product/ProductShelf.tsx";
import * as $$$$$$65 from "./sections/Product/ProductShelfTabbed.tsx";
import * as $$$$$$66 from "./sections/Product/SearchResult.tsx";
import * as $$$$$$67 from "./sections/Product/ShelfWithImage.tsx";
import * as $$$$$$68 from "./sections/Product/Wishlist.tsx";
import * as $$$$$$69 from "./sections/Social/InstagramPosts.tsx";
import * as $$$$$$70 from "./sections/Social/WhatsApp.tsx";
import * as $$$$$$71 from "./sections/Theme/Theme.tsx";

const manifest = {
"loaders": {
Expand Down Expand Up @@ -170,22 +172,24 @@ const manifest = {
"deco-sites/ecannadeco/sections/Miscellaneous/SignUp.tsx": $$$$$$52,
"deco-sites/ecannadeco/sections/Miscellaneous/Slide.tsx": $$$$$$54,
"deco-sites/ecannadeco/sections/Miscellaneous/UserAlerts.tsx": $$$$$$55,
"deco-sites/ecannadeco/sections/Newsletter/Newsletter.tsx": $$$$$$56,
"deco-sites/ecannadeco/sections/Miscellaneous/UserAssociatedSignup.tsx":
$$$$$$56,
"deco-sites/ecannadeco/sections/Newsletter/Newsletter.tsx": $$$$$$57,
"deco-sites/ecannadeco/sections/Product/ImageGalleryFrontBack.tsx":
$$$$$$57,
"deco-sites/ecannadeco/sections/Product/ImageGallerySlider.tsx": $$$$$$58,
"deco-sites/ecannadeco/sections/Product/NotFound.tsx": $$$$$$59,
"deco-sites/ecannadeco/sections/Product/NotFoundChallenge.tsx": $$$$$$60,
"deco-sites/ecannadeco/sections/Product/ProductDetails.tsx": $$$$$$61,
"deco-sites/ecannadeco/sections/Product/ProductInfo.tsx": $$$$$$62,
"deco-sites/ecannadeco/sections/Product/ProductShelf.tsx": $$$$$$63,
"deco-sites/ecannadeco/sections/Product/ProductShelfTabbed.tsx": $$$$$$64,
"deco-sites/ecannadeco/sections/Product/SearchResult.tsx": $$$$$$65,
"deco-sites/ecannadeco/sections/Product/ShelfWithImage.tsx": $$$$$$66,
"deco-sites/ecannadeco/sections/Product/Wishlist.tsx": $$$$$$67,
"deco-sites/ecannadeco/sections/Social/InstagramPosts.tsx": $$$$$$68,
"deco-sites/ecannadeco/sections/Social/WhatsApp.tsx": $$$$$$69,
"deco-sites/ecannadeco/sections/Theme/Theme.tsx": $$$$$$70,
$$$$$$58,
"deco-sites/ecannadeco/sections/Product/ImageGallerySlider.tsx": $$$$$$59,
"deco-sites/ecannadeco/sections/Product/NotFound.tsx": $$$$$$60,
"deco-sites/ecannadeco/sections/Product/NotFoundChallenge.tsx": $$$$$$61,
"deco-sites/ecannadeco/sections/Product/ProductDetails.tsx": $$$$$$62,
"deco-sites/ecannadeco/sections/Product/ProductInfo.tsx": $$$$$$63,
"deco-sites/ecannadeco/sections/Product/ProductShelf.tsx": $$$$$$64,
"deco-sites/ecannadeco/sections/Product/ProductShelfTabbed.tsx": $$$$$$65,
"deco-sites/ecannadeco/sections/Product/SearchResult.tsx": $$$$$$66,
"deco-sites/ecannadeco/sections/Product/ShelfWithImage.tsx": $$$$$$67,
"deco-sites/ecannadeco/sections/Product/Wishlist.tsx": $$$$$$68,
"deco-sites/ecannadeco/sections/Social/InstagramPosts.tsx": $$$$$$69,
"deco-sites/ecannadeco/sections/Social/WhatsApp.tsx": $$$$$$70,
"deco-sites/ecannadeco/sections/Theme/Theme.tsx": $$$$$$71,
},
"actions": {
"deco-sites/ecannadeco/actions/changePassword.ts": $$$$$$$$$0,
Expand All @@ -197,15 +201,16 @@ const manifest = {
"deco-sites/ecannadeco/actions/createTicket.ts": $$$$$$$$$6,
"deco-sites/ecannadeco/actions/deleteDocument.ts": $$$$$$$$$7,
"deco-sites/ecannadeco/actions/forgotPassword.ts": $$$$$$$$$8,
"deco-sites/ecannadeco/actions/getCids.ts": $$$$$$$$$9,
"deco-sites/ecannadeco/actions/getDocs.ts": $$$$$$$$$10,
"deco-sites/ecannadeco/actions/getPlans.ts": $$$$$$$$$11,
"deco-sites/ecannadeco/actions/getProfile.ts": $$$$$$$$$12,
"deco-sites/ecannadeco/actions/getUser.ts": $$$$$$$$$13,
"deco-sites/ecannadeco/actions/resendConfirmationCode.ts": $$$$$$$$$14,
"deco-sites/ecannadeco/actions/updateProfile.ts": $$$$$$$$$15,
"deco-sites/ecannadeco/actions/updateUserData.ts": $$$$$$$$$16,
"deco-sites/ecannadeco/actions/uploadFile.ts": $$$$$$$$$17,
"deco-sites/ecannadeco/actions/getAssociation.ts": $$$$$$$$$9,
"deco-sites/ecannadeco/actions/getCids.ts": $$$$$$$$$10,
"deco-sites/ecannadeco/actions/getDocs.ts": $$$$$$$$$11,
"deco-sites/ecannadeco/actions/getPlans.ts": $$$$$$$$$12,
"deco-sites/ecannadeco/actions/getProfile.ts": $$$$$$$$$13,
"deco-sites/ecannadeco/actions/getUser.ts": $$$$$$$$$14,
"deco-sites/ecannadeco/actions/resendConfirmationCode.ts": $$$$$$$$$15,
"deco-sites/ecannadeco/actions/updateProfile.ts": $$$$$$$$$16,
"deco-sites/ecannadeco/actions/updateUserData.ts": $$$$$$$$$17,
"deco-sites/ecannadeco/actions/uploadFile.ts": $$$$$$$$$18,
},
"apps": {
"deco-sites/ecannadeco/apps/decohub.ts": $$$$$$$$$$$0,
Expand Down
Loading

0 comments on commit 5bb3c3f

Please sign in to comment.