Skip to content

Commit

Permalink
Merge pull request #24 from deco-sites/feature/bulk-create-associatef…
Browse files Browse the repository at this point in the history
…-users

bulk create of users and make it not necessary cognito data to create…
  • Loading branch information
baufaker authored Apr 16, 2024
2 parents 2268a95 + 3f1e52c commit 04f96a4
Show file tree
Hide file tree
Showing 11 changed files with 258 additions and 49 deletions.
1 change: 0 additions & 1 deletion actions/adminGetAssociationUsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ const getAssociation = async (
});

const res = await response.json();
console.log({ responseAdminAssociationUsers: res });
return res;
} catch (e) {
// console.log({ e });
Expand Down
101 changes: 79 additions & 22 deletions components/ui/AssociationAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useEffect, useState } from "preact/hooks";
import { invoke } from "../../runtime.ts";
import PageWrap from "../../components/ui/PageWrap.tsx";
import Icon from "../../components/ui/Icon.tsx";
import PreSignupUsersModal from "../../islands/PreSignupUsersModal.tsx";
import type {
AssociationUsers,
} from "../../actions/adminGetAssociationUsers.ts";
Expand Down Expand Up @@ -36,6 +37,7 @@ function MyAccount() {
const [page, setPage] = useState<number>();
const [totalPages, setTotalPages] = useState<number>();
const [associationUsers, setAssociationUsers] = useState<AssociationUsers>();
const { displayPreSignupUsersModal } = useUI();

const handleUploadSelfie = async (
event: h.JSX.TargetedEvent<HTMLInputElement, Event>,
Expand Down Expand Up @@ -250,17 +252,29 @@ function MyAccount() {
<h2 class="text-[#8b8b8b] font-semibold mb-4 mt-10 w-full">
Pacientes da Associação
</h2>
<div>
<div class="flex flex-col sm:flex-row gap-4 justify-between mb-4">
<input
placeholder="Pesquise por email"
class="input rounded-full text-[#8b8b8b] border-none w-full disabled:bg-[#e3e3e3] sm:w-1/2 h-[35px] mb-4 text-xs"
class="input rounded-full text-[#8b8b8b] border-none w-full disabled:bg-[#e3e3e3] sm:w-1/2 h-[35px] text-xs"
name="emailSearch"
value={emailSearch}
onChange={(e) => {
setEmailSearch(e.currentTarget.value);
handleGetUsers(page!, e.currentTarget.value);
if (e.currentTarget.value.length >= 3) {
handleGetUsers(page!, e.currentTarget.value);
}
}}
/>
<div class="flex sm:w-1/2 justify-end">
<button
class="btn btn-sm btn-primary text-white"
onClick={() => {
displayPreSignupUsersModal.value = true;
}}
>
<Icon id="UserData" size={19} />Pré-cadastrar Pacientes
</button>
</div>
</div>
<div>
<div class="flex pb-2 px-2 border-b border-[#cdcdcd] mb-4">
Expand All @@ -274,35 +288,78 @@ function MyAccount() {
<span class="text-xs">CPF</span>
</div>
</div>
<PreSignupUsersModal
onFinish={() => console.log("on finish")}
/>
{isLoadingUsers
? <span>Carregando...</span>
? <span class="loading loading-spinner text-green-600"></span>
: (
<ul class="flex flex-col gap-2">
{associationUsers && associationUsers.map((u) => {
return (
<a
href={`http://localhost:8000/ficha/${u.cognito_id}`}
target="_blank"
>
<li class="p-3 bg-[#cacaca] flex gap-[2%] justify-between items-center rounded-md text-[10px] sm:text-xs md:text-sm">
<div class="w-[32%] flex justify-start">
<span>{u.cognito_data.name}</span>
</div>
<div class="w-[32%] flex justify-start">
<span>{u.email}</span>
</div>
<div class="w-[32%] flex justify-end">
<span>{u.cognito_data.cpf}</span>
<div class="dropdown dropdown-top dropdown-end">
<div tabindex={0} role="button" class="">
<div target="_blank">
<li class="p-3 bg-[#cacaca] flex gap-[2%] justify-between items-center rounded-md text-[10px] sm:text-xs md:text-sm">
<div class="w-[32%] flex justify-start">
<span>
{u.cognito_data
? u.cognito_data.name
: (
<span class="badge text-xs font-bold">
Cadastro Pendente
</span>
)}
</span>
</div>
<div class="w-[32%] flex justify-start">
<span>{u.email}</span>
</div>
<div class="w-[32%] flex justify-end">
<span>
{u.cognito_data
? u.cognito_data.cpf
: (
<span class="badge text-xs font-bold">
Cadastro Pendente
</span>
)}
</span>
</div>
</li>
</div>
</li>
</a>
</div>
<ul
tabindex={0}
class="dropdown-content z-[1] menu p-2 shadow bg-base-100 rounded-box w-52"
>
<span class="text-[10px] font-bold text-center">
{u.email}
</span>
<li>
<a
href={`http://localhost:8000/ficha/${u._id}`}
target="_blank"
class="flex items-center"
>
Ficha do Paciente
</a>
</li>
<li>
<a>Baixar QR Code</a>
</li>
<li>
<a>Subir Documento</a>
</li>
</ul>
</div>
);
})}
</ul>
)}
</div>
{/* pagination */}
<div class="flex justify-center mt-4 font-xs">
<div class="flex justify-center mt-4">
<div>
{hasPrevPage && (
<Icon
Expand All @@ -313,8 +370,8 @@ function MyAccount() {
)}
</div>
<div>
<span>
{isLoadingUsers ? "..." : `Página ${page}/${totalPages}`}
<span class="text-xs">
{`Página ${page}/${totalPages}`}
</span>
</div>
<div>
Expand Down
1 change: 1 addition & 0 deletions components/ui/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type AvailableIcons =
| "FilterList"
| "Heart"
| "Instagram"
| "QRicon"
| "CircleCheck"
| "Linkedin"
| "Minus"
Expand Down
2 changes: 1 addition & 1 deletion components/ui/OrderStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function OrderStatus({ status }: Props) {

return (
<span
class={`badge badge-sm border-none text-white text-[10px] sm:text-xs md:text-sm ${
class={`badge badge-sm border-none text-white text-[10px] sm:text-xs ${
style[status].style
}`}
>
Expand Down
83 changes: 83 additions & 0 deletions components/ui/PreSignupUsersModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import Modal from "../../components/ui/Modal.tsx";
import Icon from "../../components/ui/Icon.tsx";
import { useState } from "preact/hooks";
import { useUI } from "../../sdk/useUI.ts";
import { h } from "preact";

export interface Props {
onFinish: () => void;
}

const PreSignupUsersModal = ({ onFinish }: Props) => {
const [file, setFile] = useState<File>();
const { displayPreSignupUsersModal } = useUI();
const [isUploading, setIsUploading] = useState(false);

const handleStoreDocument = (
event: h.JSX.TargetedEvent<HTMLInputElement, Event>,
) => {
const fileInput = event.target as HTMLInputElement;
if (fileInput.files) {
setFile(fileInput.files[0]);
}
};

const handleCreate = () => {
setIsUploading(true);

try {
console.log("oi");
} catch (e) {
console.log({ erroUpload: e });
setIsUploading(false);
}
};

return (
<Modal
loading="lazy"
open={displayPreSignupUsersModal.value}
onClose={() => displayPreSignupUsersModal.value = false}
>
<div class="flex flex-col p-16 gap-3 bg-[#EDEDED] rounded-xl max-w-[90%] sm:max-w-[500px]">
<h3 class="text-2xl text-[#8b8b8b] font-semibold text-center">
Pré Cadastrar Pacientes Associados
</h3>
<span class="text-center text-xs">
Suba arquivo csv com as colunas <span class="font-bold">email</span> e
{" "}
<span class="font-bold">cids</span>{" "}
dos pacientes que deseja pré-cadastrar na sua associação.
</span>

<label class="form-control w-full max-w-xs">
<div class="label">
<span class="label-text">Selecionar arquivo csv</span>
</div>
<input
type="file"
accept=".csv"
class="file-input file-input-primary w-full max-w-xs"
onChange={(e) => handleStoreDocument(e)}
/>
</label>

<button class="btn btn-secondary text-white" onClick={handleCreate}>
Fazer Pré Cadastro{" "}{isUploading
? <span class="loading loading-spinner text-white"></span>
: <Icon id="UserData" size={24} />}
</button>
<button
onClick={() => {
displayPreSignupUsersModal.value = false;
}}
class="btn btn-ghost uppercase font-medium"
>
Cancelar
</button>
</div>
</Modal>
);
};

export default PreSignupUsersModal;
100 changes: 77 additions & 23 deletions components/ui/PublicProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,22 @@ interface Props {
function PublicProfileComponent(
{ publicProfile }: Props,
) {
const { cpf, name, cids, plan, documents, avatar_photo, association } =
publicProfile;
const {
cpf,
name,
cids,
plan,
documents,
avatar_photo,
association,
_id,
email,
} = publicProfile;

console.log({ publicProfile });
return (
<PageWrap>
{!publicProfile.cpf
{!_id
? <span>Usuário não encontrado</span>
: (
<div class="flex flex-col items-center gap-5 max-w-[95%]">
Expand All @@ -26,19 +37,44 @@ function PublicProfileComponent(
</div>
<Image
class="rounded-md"
src={avatar_photo}
src={avatar_photo
? avatar_photo
: "http://drive.google.com/uc?export=view&id=1tSFTp0YZKVQVGJHOqzKaJw6SEe7Q8LL7"}
alt={"user selfie"}
width={108}
height={144}
/>
<div class="flex flex-col items-center">
<span class="text-2xl text-secondary font-semibold">{name}</span>
<span class="text-secondary font-semibold">
CPF:{" " + cpf.replace(
/(\d{3})(\d{3})(\d{3})(\d{2})/,
"$1.$2.$3-$4",
{name && cpf
? (
<div class="flex flex-col items-center">
<span class="text-2xl text-secondary font-semibold">
{name}
</span>
<span class="text-secondary font-semibold">
CPF:{" " + cpf.replace(
/(\d{3})(\d{3})(\d{3})(\d{2})/,
"$1.$2.$3-$4",
)}
</span>
</div>
)
: (
<div class="p-3 flex flex-col items-center text-[#5e5e5e] text-sm bg-[#cecece] rounded-md gap-3">
<span class="text-center">
Informação Pendente: Paciente deve fazer cadastro com
email <span class="font-bold">{email}</span>{" "}
e atualizar dados médicos / pessoais.
</span>
<a
href="/cadastrar"
class="btn btn-primary btn-xs text-white"
>
Clique aqui para cadastrar
</a>
</div>
)}
</span>

{association && (
<div class="flex flex-col items-center mt-4">
<span class="text-[#5B5B5B] font-semibold text-sm">
Expand All @@ -57,19 +93,37 @@ function PublicProfileComponent(
<h2 class="text-[#8b8b8b] font-semibold mb-4 mt-10 w-full">
CIDs (Diagnósticos)
</h2>
<ul class="flex flex-col gap-2 max-w-[100%]">
{cids.map((c) => {
return (
<li>
<div class="badge badge-secondary text-white gap-2 p-3 max-w-[100%]">
<span class="text-[10px] sm:text-sm truncate">
CID{" " + c.full_code + " - " + c.name}
</span>
</div>
</li>
);
})}
</ul>
{cids && cids.length
? (
<ul class="flex flex-col gap-2 max-w-[100%]">
{cids.map((c) => {
return (
<li>
<div class="badge badge-secondary text-white gap-2 p-3 max-w-[100%]">
<span class="text-[10px] sm:text-sm truncate">
CID{" " + c.full_code + " - " + c.name}
</span>
</div>
</li>
);
})}
</ul>
)
: (
<div class="p-3 flex flex-col items-center text-[#5e5e5e] text-sm bg-[#cecece] rounded-md gap-3">
<span class="text-center">
Informação Pendente: Paciente deve fazer cadastro com
email <span class="font-bold">{email}</span>{" "}
e atualizar dados médicos / pessoais.
</span>
<a
href="/cadastrar"
class="btn btn-primary btn-xs text-white"
>
Clique aqui para cadastrar
</a>
</div>
)}
</div>
<div class="flex flex-col items-start w-full">
<h2 class="text-[#8b8b8b] font-semibold mb-4 mt-10 w-full">
Expand Down
Loading

0 comments on commit 04f96a4

Please sign in to comment.