From 69970e2c95fc5f5d07deef45759260a81dc1e280 Mon Sep 17 00:00:00 2001 From: andradeviniicius Date: Thu, 16 May 2024 22:29:06 -0300 Subject: [PATCH 01/24] fix/ add lucide icons to replace emojis so it works across all browsers --- src/pages/AboutUs/AboutUs.tsx | 22 +++++++---- .../AboutUs/{frontItems.ts => frontItems.tsx} | 39 ++++++++++++------- src/pages/Home/components/Filter/types.ts | 2 +- 3 files changed, 41 insertions(+), 22 deletions(-) rename src/pages/AboutUs/{frontItems.ts => frontItems.tsx} (67%) diff --git a/src/pages/AboutUs/AboutUs.tsx b/src/pages/AboutUs/AboutUs.tsx index 080c909e..f66ef145 100644 --- a/src/pages/AboutUs/AboutUs.tsx +++ b/src/pages/AboutUs/AboutUs.tsx @@ -1,5 +1,5 @@ import { useMemo } from 'react'; -import { HandHeart, Home, Loader, Users } from 'lucide-react'; +import { HandHeart, Home, LifeBuoy, Loader, Users } from 'lucide-react'; import { BurgerMenu, Header } from '@/components'; import { AboutCardInfo, ServicedFrontInfo } from './components'; @@ -43,8 +43,12 @@ const AboutUs = () => {

Iniciado no domingo (04/05) e concluído na segunda (05/05), após 18 - horas seguidas de desenvolvimento, nosso webapp SOS RS 🛟, - idealizado e desenvolvido por{' '} + horas seguidas de desenvolvimento, nosso webapp SOS RS + + , idealizado e desenvolvido por{' '} { className="w-full" /> -

- Atualmente, o SOS RS 🛟 apoia a gestão das demandas e - necessidades dos abrigos do Rio Grande do Sul com informações - públicas, atualizadas, confiáveis e auditáveis. +

+ Atualmente, o SOS RS + {' '} + apoia a gestão das demandas e necessidades dos abrigos do Rio Grande + do Sul com informações públicas, atualizadas, confiáveis e auditáveis.

Frentes atendidas diff --git a/src/pages/AboutUs/frontItems.ts b/src/pages/AboutUs/frontItems.tsx similarity index 67% rename from src/pages/AboutUs/frontItems.ts rename to src/pages/AboutUs/frontItems.tsx index 61797ff0..cb05f6c3 100644 --- a/src/pages/AboutUs/frontItems.ts +++ b/src/pages/AboutUs/frontItems.tsx @@ -1,68 +1,79 @@ import { IServicedFrontInfoProps } from './components/ServicedFrontInfo/types'; +import { + Car, + Baby, + MapPinned, + CookingPot, + GlassWater, + Goal, + HeartHandshake, + Infinity, + MonitorSmartphone, + Speech, + Users, +} from 'lucide-react'; -const frontItems: IServicedFrontInfoProps[] = [ +export const frontItems: IServicedFrontInfoProps[] = [ { - icon: '🚰', + icon: , title: 'Água', description: 'Atender demandas urgentes de água;', }, { - icon: '🥘', + icon: , title: 'Cozinhas solidárias', description: 'Auxiliar na operação das cozinhas com o envio de suprimentos e distribuição das marmitas;', }, { - icon: '🏠', + icon: , title: 'Conexões', description: 'Gerir dados confiáveis sobre a demanda de abrigos e a disponibilidade de doações;', }, { - icon: '️❤️', + icon: , title: 'Comunidades', description: 'Mapear e integrar lideranças comunitárias;', }, { - icon: '📣', + icon: , title: 'Comunicação', description: 'Manter as informações sobre a iniciativa atualizadas e disponíveis a todos;', }, { - icon: '📍', + icon: , title: 'Dados e Geolocalização', description: 'Fornecer dados públicos sobre as enchentes e as demandas do cenário de crise com o apoio do IPH UFRGS e nossas operações de voluntários;', }, { - icon: '🎯', + icon: , title: 'Expansão', description: 'Estruturar o crescimento da operação e parcerias;', }, { - icon: '️🚗', + icon: , title: 'Logística', description: 'Conectar o transporte dos centros de distribuição e triagem aos abrigos;', }, { - icon: '🧒🏽', + icon: , title: 'Olhar para a criança', description: 'Proteger e oferecer apoio às crianças em abrigos;', }, { - icon: '️🧑🏽‍🤝‍🧑🏽', + icon: , title: 'Pessoas', description: 'Recrutar, acolher, orientar, treinar e direcionar novos voluntários e padrinhos/madrinhas;', }, { - icon: '🖥️', + icon: , title: 'Tecnologia', description: 'Desenvolver uma solução digital a partir de dados públicos confiáveis.', }, ]; - -export { frontItems }; diff --git a/src/pages/Home/components/Filter/types.ts b/src/pages/Home/components/Filter/types.ts index 356af68e..c06adb68 100644 --- a/src/pages/Home/components/Filter/types.ts +++ b/src/pages/Home/components/Filter/types.ts @@ -28,6 +28,6 @@ export interface IFilterFormikProps { export interface IFilterProps { onSubmit: (values: IFilterFormProps) => void; data: IFilterFormProps; - open: true; + open: boolean; onClose: () => void; } From e17170fb3ef27070e913d617b10d3772169420d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Fagundes?= Date: Fri, 17 May 2024 17:15:16 -0300 Subject: [PATCH 02/24] feat: added shelter category --- .../Authenticated/Authenticated.tsx | 8 +- src/components/Authenticated/types.ts | 1 + src/components/BurgerMenu/BurgerMenu.tsx | 19 +++-- .../BurguerMenuItem/BurguerMenuItem.tsx | 14 +++- .../components/BurguerMenuItem/types.ts | 1 + .../CardAboutShelter/CardAboutShelter.tsx | 78 +++++++++-------- .../components/InfoRow/InfoRow.tsx | 1 - src/hooks/useShelter/types.ts | 7 ++ src/hooks/useShelters/types.ts | 3 + src/lib/utils.ts | 18 ++-- src/pages/Home/components/Filter/Filter.tsx | 4 +- .../ShelterListItem/ShelterListItem.tsx | 39 +++++++-- src/pages/Shelter/Shelter.tsx | 31 ++++--- src/pages/UpdateShelter/UpdateShelter.tsx | 83 +++++++++++-------- 14 files changed, 202 insertions(+), 105 deletions(-) diff --git a/src/components/Authenticated/Authenticated.tsx b/src/components/Authenticated/Authenticated.tsx index 9b51d6d0..7e4b88e8 100644 --- a/src/components/Authenticated/Authenticated.tsx +++ b/src/components/Authenticated/Authenticated.tsx @@ -3,10 +3,14 @@ import { Fragment } from 'react'; import { IAuthenticatedProps } from './types'; import { useAuthRoles } from '@/hooks'; -const Authenticated = ({ children, role = 'User' }: IAuthenticatedProps) => { +const Authenticated = ({ + children, + bypass = false, + role = 'User', +}: IAuthenticatedProps) => { const isAuthenticated = useAuthRoles(role); - if (!isAuthenticated) return ; + if (!bypass && !isAuthenticated) return ; return
{children}
; }; diff --git a/src/components/Authenticated/types.ts b/src/components/Authenticated/types.ts index 224d8d08..8cf9397f 100644 --- a/src/components/Authenticated/types.ts +++ b/src/components/Authenticated/types.ts @@ -2,5 +2,6 @@ import { AccessLevel } from '@/service/sessions/types'; export interface IAuthenticatedProps { role?: AccessLevel; + bypass?: boolean; children?: React.ReactNode; } diff --git a/src/components/BurgerMenu/BurgerMenu.tsx b/src/components/BurgerMenu/BurgerMenu.tsx index 526a5e02..2f823e5b 100644 --- a/src/components/BurgerMenu/BurgerMenu.tsx +++ b/src/components/BurgerMenu/BurgerMenu.tsx @@ -7,6 +7,7 @@ import { Info, LinkIcon, Menu, + ShieldAlert, } from 'lucide-react'; import { SessionServices } from '@/service'; @@ -49,27 +50,35 @@ const BurgerMenu = () => { } + icon={} /> } + icon={} + openExternal={true} + /> + } + openExternal={true} /> } + icon={} + openExternal={true} /> } + icon={} /> } + icon={} /> {partners.length > 0 && ( diff --git a/src/components/BurgerMenu/components/BurguerMenuItem/BurguerMenuItem.tsx b/src/components/BurgerMenu/components/BurguerMenuItem/BurguerMenuItem.tsx index 98d8a4c4..6f42570f 100644 --- a/src/components/BurgerMenu/components/BurguerMenuItem/BurguerMenuItem.tsx +++ b/src/components/BurgerMenu/components/BurguerMenuItem/BurguerMenuItem.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { ExternalLink } from 'lucide-react'; import { IBurguerMenuItemProps } from './types'; import { cn } from '@/lib/utils'; @@ -7,22 +8,31 @@ const BurguerMenuItem = React.forwardRef< HTMLAnchorElement, IBurguerMenuItemProps >((props, ref) => { - const { icon, label, onClick, link, className = '', ...rest } = props; + const { + icon, + label, + onClick, + link, + className = '', + openExternal, + ...rest + } = props; return (
{icon} {label} + {openExternal && } ); }); diff --git a/src/components/BurgerMenu/components/BurguerMenuItem/types.ts b/src/components/BurgerMenu/components/BurguerMenuItem/types.ts index d48e5ec0..e426a078 100644 --- a/src/components/BurgerMenu/components/BurguerMenuItem/types.ts +++ b/src/components/BurgerMenu/components/BurguerMenuItem/types.ts @@ -3,5 +3,6 @@ export interface IBurguerMenuItemProps label: string; icon?: React.ReactNode; link?: string; + openExternal?: boolean; onClick?: () => void; } diff --git a/src/components/CardAboutShelter/CardAboutShelter.tsx b/src/components/CardAboutShelter/CardAboutShelter.tsx index cff1ea22..34525112 100644 --- a/src/components/CardAboutShelter/CardAboutShelter.tsx +++ b/src/components/CardAboutShelter/CardAboutShelter.tsx @@ -13,6 +13,8 @@ import { Card } from '../ui/card'; import { ICardAboutShelter } from './types'; import { InfoRow } from './components'; import { checkAndFormatAddress } from './utils'; +import { ShelterCategory } from '@/hooks/useShelter/types'; +import { Fragment } from 'react/jsx-runtime'; const CardAboutShelter = (props: ICardAboutShelter) => { const { shelter } = props; @@ -33,42 +35,46 @@ const CardAboutShelter = (props: ICardAboutShelter) => { {Boolean(shelter.zipCode) && ( } label="CEP:" value={shelter.zipCode} /> )} - } - label={ - check(shelter.petFriendly) ? ( - shelter.petFriendly ? ( -

- O abrigo aceita animais -

- ) : ( -

- O abrigo não aceita animais -

- ) - ) : ( - Não informado se aceita animais - ) - } - /> - } - label="Pessoas abrigadas:" - value={ - check(shelter.shelteredPeople) - ? `${shelter.shelteredPeople} pessoas` - : 'Não informado' - } - /> - } - label="Capacidade do abrigo:" - value={ - check(shelter.capacity) - ? `${shelter.capacity} pessoas` - : 'Não informado' - } - /> + {shelter.category === ShelterCategory.Shelter && ( + + } + label={ + check(shelter.petFriendly) ? ( + shelter.petFriendly ? ( +

+ O abrigo aceita animais +

+ ) : ( +

+ O abrigo não aceita animais +

+ ) + ) : ( + Não informado se aceita animais + ) + } + /> + } + label="Pessoas abrigadas:" + value={ + check(shelter.shelteredPeople) + ? `${shelter.shelteredPeople} pessoas` + : 'Não informado' + } + /> + } + label="Capacidade do abrigo:" + value={ + check(shelter.capacity) + ? `${shelter.capacity} pessoas` + : 'Não informado' + } + /> +
+ )} } label="Contato:" diff --git a/src/components/CardAboutShelter/components/InfoRow/InfoRow.tsx b/src/components/CardAboutShelter/components/InfoRow/InfoRow.tsx index da5007a2..9b70fb2a 100644 --- a/src/components/CardAboutShelter/components/InfoRow/InfoRow.tsx +++ b/src/components/CardAboutShelter/components/InfoRow/InfoRow.tsx @@ -18,7 +18,6 @@ const InfoRow = React.forwardRef( ) : isLink ? ( {value} diff --git a/src/hooks/useShelter/types.ts b/src/hooks/useShelter/types.ts index 83a61d41..22c3bd67 100644 --- a/src/hooks/useShelter/types.ts +++ b/src/hooks/useShelter/types.ts @@ -1,3 +1,8 @@ +export enum ShelterCategory { + Shelter = 'Shelter', + DistributionCenter = 'DistributionCenter', +} + export interface IUseShelterData { id: string; name: string; @@ -17,6 +22,8 @@ export interface IUseShelterData { latitude?: string | null; longitude?: string | null; shelterSupplies: IUseShelterDataSupply[]; + category: ShelterCategory; + actived: boolean; createdAt: string; updatedAt?: string | null; } diff --git a/src/hooks/useShelters/types.ts b/src/hooks/useShelters/types.ts index 8cf76801..057bfcbe 100644 --- a/src/hooks/useShelters/types.ts +++ b/src/hooks/useShelters/types.ts @@ -1,4 +1,5 @@ import { ShelterTagType } from '@/pages/Home/components/ShelterListItem/types'; +import { ShelterCategory } from '../useShelter/types'; export interface IUseSheltersData { id: string; @@ -18,6 +19,8 @@ export interface IUseSheltersData { verified: boolean; latitude?: string | null; longitude?: string | null; + category: ShelterCategory; + actived: boolean; createdAt: string; updatedAt?: string | null; shelterSupplies: IUseSheltersDataSupplyData[]; diff --git a/src/lib/utils.ts b/src/lib/utils.ts index a037935c..dc8981ac 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,3 +1,4 @@ +import { ShelterCategory } from '@/hooks/useShelter/types'; import { IUseSheltersDataSupplyData } from '@/hooks/useShelters/types'; import { ShelterTagInfo, @@ -41,11 +42,18 @@ function nameStatusPriority(priority: SupplyPriority) { if (priority === SupplyPriority.Remaining) return 'Disponível para doação'; } -function getAvailabilityProps( - capacity?: number | null, - shelteredPeople?: number | null -) { - if (capacity && (shelteredPeople || shelteredPeople === 0)) { +function getAvailabilityProps(props: { + capacity?: number | null; + shelteredPeople?: number | null; + category: ShelterCategory; +}) { + const { category, capacity, shelteredPeople } = props; + if (category === ShelterCategory.DistributionCenter) { + return { + availability: 'Centro de Distribuição', + className: 'text-green-600', + }; + } else if (capacity && (shelteredPeople || shelteredPeople === 0)) { if (shelteredPeople < capacity) return { availability: 'Abrigo disponível', diff --git a/src/pages/Home/components/Filter/Filter.tsx b/src/pages/Home/components/Filter/Filter.tsx index b63884bb..344fddd6 100644 --- a/src/pages/Home/components/Filter/Filter.tsx +++ b/src/pages/Home/components/Filter/Filter.tsx @@ -149,14 +149,14 @@ const Filter = (props: IFilterProps) => { return ( - + Faça sua busca:
-
+
{ + if (active) return {children}; + else + return ( +
+ {children} +
+ ); +}; + const ShelterListItem = (props: IShelterListItemProps) => { const { data } = props; const { capacity, shelteredPeople } = data; const { availability, className: availabilityClassName } = useMemo( - () => getAvailabilityProps(capacity, shelteredPeople), - [capacity, shelteredPeople] + () => + getAvailabilityProps({ + capacity, + shelteredPeople, + category: data.category, + }), + [capacity, shelteredPeople, data.category] ); const tags: ShelterTagInfo = useMemo(() => { @@ -45,7 +68,7 @@ const ShelterListItem = (props: IShelterListItemProps) => { : '(sem informação)'; return ( - +
@@ -58,9 +81,11 @@ const ShelterListItem = (props: IShelterListItemProps) => {
)}
- + {data.actived && ( + + )}
{availability} @@ -88,7 +113,7 @@ const ShelterListItem = (props: IShelterListItemProps) => { Atualizado em {updatedAtDate}
- + ); }; diff --git a/src/pages/Shelter/Shelter.tsx b/src/pages/Shelter/Shelter.tsx index b3473806..78fea039 100644 --- a/src/pages/Shelter/Shelter.tsx +++ b/src/pages/Shelter/Shelter.tsx @@ -1,6 +1,7 @@ import { useCallback, useMemo, useState } from 'react'; import { ChevronLeft, Pencil } from 'lucide-react'; import { useNavigate, useParams } from 'react-router-dom'; +import { format } from 'date-fns'; import { Authenticated, @@ -22,7 +23,7 @@ import { VerifiedBadge } from '@/components/VerifiedBadge/VerifiedBadge.tsx'; import { ShelterSupplyServices } from '@/service'; import { useToast } from '@/components/ui/use-toast'; import { clearCache } from '@/api/cache'; -import { format } from 'date-fns'; +import { ShelterCategory } from '@/hooks/useShelter/types'; const Shelter = () => { const params = useParams(); @@ -47,8 +48,13 @@ const Shelter = () => { }, [shelter?.shelterSupplies]); const { availability, className: availabilityClassName } = useMemo( - () => getAvailabilityProps(shelter?.capacity, shelter?.shelteredPeople), - [shelter?.capacity, shelter?.shelteredPeople] + () => + getAvailabilityProps({ + capacity: shelter?.capacity, + shelteredPeople: shelter?.shelteredPeople, + category: shelter?.category, + }), + [shelter?.capacity, shelter?.shelteredPeople, shelter?.category] ); const [loadingUpdateMany, setLoadingUpdateMany] = useState(false); const { toast } = useToast(); @@ -112,14 +118,19 @@ const Shelter = () => {

{availability}

- + +
diff --git a/src/pages/UpdateShelter/UpdateShelter.tsx b/src/pages/UpdateShelter/UpdateShelter.tsx index a85a6f99..c1c8f739 100644 --- a/src/pages/UpdateShelter/UpdateShelter.tsx +++ b/src/pages/UpdateShelter/UpdateShelter.tsx @@ -1,4 +1,4 @@ -import { useContext, useEffect } from 'react'; +import { Fragment, useContext, useEffect } from 'react'; import { ChevronLeft, Loader } from 'lucide-react'; import { useNavigate, useParams } from 'react-router-dom'; import { useFormik } from 'formik'; @@ -23,6 +23,7 @@ import { useDebouncedValue, useViaCep } from '@/hooks'; import { cn } from '@/lib/utils'; import { FullUpdateShelterSchema, UpdateShelterSchema } from './types'; import { useAuthRoles } from '@/hooks/useAuthRoles/useAuthRoles'; +import { ShelterCategory } from '@/hooks/useShelter/types'; const UpdateShelter = () => { const navigate = useNavigate(); @@ -117,9 +118,9 @@ const UpdateShelter = () => { />
-
Atualizar abrigo
+
Atualização cadastral

- Atualize as informações desejadas sobre o abrigo. + Atualize as informações desejadas.

@@ -194,40 +195,52 @@ const UpdateShelter = () => { error={!!errors.contact} helperText={errors.contact} /> - + {shelter.category === ShelterCategory.Shelter && ( + + )} - - setFieldValue('petFriendly', v === 'true')} - options={[ - { value: 'true', label: 'Sim' }, - { value: 'false', label: 'Não' }, - ]} - /> + {shelter.category === ShelterCategory.Shelter && ( + + + + setFieldValue('petFriendly', v === 'true') + } + options={[ + { value: 'true', label: 'Sim' }, + { value: 'false', label: 'Não' }, + ]} + /> + + + setFieldValue('verified', v === 'true') + } + options={[ + { value: 'true', label: 'Sim' }, + { value: 'false', label: 'Não' }, + ]} + /> + + + )} - setFieldValue('verified', v === 'true')} - options={[ - { value: 'true', label: 'Sim' }, - { value: 'false', label: 'Não' }, - ]} - /> Date: Sun, 19 May 2024 20:08:55 -0300 Subject: [PATCH 03/24] setup shadcdn combobox --- package-lock.json | 52 ++++++++++++ package.json | 8 +- src/components/ui/command.tsx | 153 ++++++++++++++++++++++++++++++++++ src/components/ui/popover.tsx | 29 +++++++ 4 files changed, 239 insertions(+), 3 deletions(-) create mode 100644 src/components/ui/command.tsx create mode 100644 src/components/ui/popover.tsx diff --git a/package-lock.json b/package-lock.json index 33731021..06f7d6a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", "@radix-ui/react-label": "^2.0.2", + "@radix-ui/react-popover": "^1.0.7", "@radix-ui/react-radio-group": "^1.1.3", "@radix-ui/react-select": "^2.0.0", "@radix-ui/react-separator": "^1.0.3", @@ -22,6 +23,7 @@ "axios": "^1.6.8", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", + "cmdk": "^1.0.0", "date-fns": "^3.6.0", "formik": "^2.4.6", "lucide-react": "^0.378.0", @@ -1597,6 +1599,43 @@ } } }, + "node_modules/@radix-ui/react-popover": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/@radix-ui/react-popover/-/react-popover-1.0.7.tgz", + "integrity": "sha512-shtvVnlsxT6faMnK/a7n0wptwBD23xc1Z5mdrtKLwVEfsEMXodS0r5s0/g5P0hX//EKYZS2sxUjqfzlg52ZSnQ==", + "dependencies": { + "@babel/runtime": "^7.13.10", + "@radix-ui/primitive": "1.0.1", + "@radix-ui/react-compose-refs": "1.0.1", + "@radix-ui/react-context": "1.0.1", + "@radix-ui/react-dismissable-layer": "1.0.5", + "@radix-ui/react-focus-guards": "1.0.1", + "@radix-ui/react-focus-scope": "1.0.4", + "@radix-ui/react-id": "1.0.1", + "@radix-ui/react-popper": "1.1.3", + "@radix-ui/react-portal": "1.0.4", + "@radix-ui/react-presence": "1.0.1", + "@radix-ui/react-primitive": "1.0.3", + "@radix-ui/react-slot": "1.0.2", + "@radix-ui/react-use-controllable-state": "1.0.1", + "aria-hidden": "^1.1.1", + "react-remove-scroll": "2.5.5" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0", + "react-dom": "^16.8 || ^17.0 || ^18.0" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-popper": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.1.3.tgz", @@ -2992,6 +3031,19 @@ "node": ">=6" } }, + "node_modules/cmdk": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/cmdk/-/cmdk-1.0.0.tgz", + "integrity": "sha512-gDzVf0a09TvoJ5jnuPvygTB77+XdOSwEmJ88L6XPFPlv7T3RxbP9jgenfylrAMD0+Le1aO0nVjQUzl2g+vjz5Q==", + "dependencies": { + "@radix-ui/react-dialog": "1.0.5", + "@radix-ui/react-primitive": "1.0.3" + }, + "peerDependencies": { + "react": "^18.0.0", + "react-dom": "^18.0.0" + } + }, "node_modules/color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", diff --git a/package.json b/package.json index 29dd3ef1..a2cd15f5 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", "@radix-ui/react-label": "^2.0.2", + "@radix-ui/react-popover": "^1.0.7", "@radix-ui/react-radio-group": "^1.1.3", "@radix-ui/react-select": "^2.0.0", "@radix-ui/react-separator": "^1.0.3", @@ -24,16 +25,17 @@ "axios": "^1.6.8", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", + "cmdk": "^1.0.0", "date-fns": "^3.6.0", "formik": "^2.4.6", "lucide-react": "^0.378.0", "qs": "^6.12.1", + "react": "^18.2.0", "react-dom": "^18.2.0", "react-hook-form": "^7.51.4", "react-input-mask": "^2.0.4", "react-router-dom": "^6.23.0", "react-select": "^5.8.0", - "react": "^18.2.0", "tailwind-merge": "^2.3.0", "tailwindcss-animate": "^1.0.7", "yup": "^1.4.0" @@ -41,16 +43,16 @@ "devDependencies": { "@types/node": "^20.12.8", "@types/qs": "^6.9.15", + "@types/react": "^18.2.66", "@types/react-dom": "^18.2.22", "@types/react-input-mask": "^3.0.5", - "@types/react": "^18.2.66", "@typescript-eslint/eslint-plugin": "^7.2.0", "@typescript-eslint/parser": "^7.2.0", "@vitejs/plugin-react": "^4.2.1", "autoprefixer": "^10.4.19", + "eslint": "^8.57.0", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.4.6", - "eslint": "^8.57.0", "postcss": "^8.4.38", "tailwindcss": "^3.4.3", "typescript": "^5.2.2", diff --git a/src/components/ui/command.tsx b/src/components/ui/command.tsx new file mode 100644 index 00000000..dd2e876e --- /dev/null +++ b/src/components/ui/command.tsx @@ -0,0 +1,153 @@ +import * as React from "react" +import { type DialogProps } from "@radix-ui/react-dialog" +import { Command as CommandPrimitive } from "cmdk" +import { Search } from "lucide-react" + +import { cn } from "@/lib/utils" +import { Dialog, DialogContent } from "@/components/ui/dialog" + +const Command = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +Command.displayName = CommandPrimitive.displayName + +interface CommandDialogProps extends DialogProps {} + +const CommandDialog = ({ children, ...props }: CommandDialogProps) => { + return ( + + + + {children} + + + + ) +} + +const CommandInput = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( +
+ + +
+)) + +CommandInput.displayName = CommandPrimitive.Input.displayName + +const CommandList = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) + +CommandList.displayName = CommandPrimitive.List.displayName + +const CommandEmpty = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>((props, ref) => ( + +)) + +CommandEmpty.displayName = CommandPrimitive.Empty.displayName + +const CommandGroup = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) + +CommandGroup.displayName = CommandPrimitive.Group.displayName + +const CommandSeparator = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) +CommandSeparator.displayName = CommandPrimitive.Separator.displayName + +const CommandItem = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + +)) + +CommandItem.displayName = CommandPrimitive.Item.displayName + +const CommandShortcut = ({ + className, + ...props +}: React.HTMLAttributes) => { + return ( + + ) +} +CommandShortcut.displayName = "CommandShortcut" + +export { + Command, + CommandDialog, + CommandInput, + CommandList, + CommandEmpty, + CommandGroup, + CommandItem, + CommandShortcut, + CommandSeparator, +} diff --git a/src/components/ui/popover.tsx b/src/components/ui/popover.tsx new file mode 100644 index 00000000..bbba7e0e --- /dev/null +++ b/src/components/ui/popover.tsx @@ -0,0 +1,29 @@ +import * as React from "react" +import * as PopoverPrimitive from "@radix-ui/react-popover" + +import { cn } from "@/lib/utils" + +const Popover = PopoverPrimitive.Root + +const PopoverTrigger = PopoverPrimitive.Trigger + +const PopoverContent = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( + + + +)) +PopoverContent.displayName = PopoverPrimitive.Content.displayName + +export { Popover, PopoverTrigger, PopoverContent } From 450a44bdd847d34d4d99d22ac01d06b3ca44ec37 Mon Sep 17 00:00:00 2001 From: Larissa Pissurno Date: Sun, 19 May 2024 20:14:35 -0300 Subject: [PATCH 04/24] remove new item btn --- src/pages/EditShelterSupply/EditShelterSupply.tsx | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/pages/EditShelterSupply/EditShelterSupply.tsx b/src/pages/EditShelterSupply/EditShelterSupply.tsx index c7729e6e..6d53bbdb 100644 --- a/src/pages/EditShelterSupply/EditShelterSupply.tsx +++ b/src/pages/EditShelterSupply/EditShelterSupply.tsx @@ -166,14 +166,6 @@ const EditShelterSupply = () => { Para cada item da lista abaixo, informe a disponibilidade no abrigo selecionado

-
Date: Sun, 19 May 2024 23:30:42 -0300 Subject: [PATCH 05/24] add autocomplete with search --- .../EditShelterSupply/EditShelterSupply.tsx | 53 ++++++++++++---- .../components/SupplySearch/SupplySearch.tsx | 62 +++++++++++++++++++ 2 files changed, 102 insertions(+), 13 deletions(-) create mode 100644 src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx diff --git a/src/pages/EditShelterSupply/EditShelterSupply.tsx b/src/pages/EditShelterSupply/EditShelterSupply.tsx index 6d53bbdb..e2d47a06 100644 --- a/src/pages/EditShelterSupply/EditShelterSupply.tsx +++ b/src/pages/EditShelterSupply/EditShelterSupply.tsx @@ -1,4 +1,4 @@ -import { ChevronLeft, PlusCircle } from 'lucide-react'; +import { ChevronLeft } from 'lucide-react'; import { useNavigate, useParams } from 'react-router-dom'; import { Fragment, useCallback, useEffect, useMemo, useState } from 'react'; @@ -15,6 +15,7 @@ import { SupplyPriority } from '@/service/supply/types'; import { IUseShelterDataSupply } from '@/hooks/useShelter/types'; import { clearCache } from '@/api/cache'; import { IUseSuppliesData } from '@/hooks/useSupplies/types'; +import { SupplySearch } from './components/SupplySearch/SupplySearch'; const EditShelterSupply = () => { const navigate = useNavigate(); @@ -25,16 +26,38 @@ const EditShelterSupply = () => { const [filteredSupplies, setFilteredSupplies] = useState( [] ); - const [searchValue, setSearchValue] = useState(''); - const [, setSearch] = useThrottle( + const [searchedSupplies, setSearchedSupplies] = useState( + [] + ); + const [, setSearchSupplies] = useThrottle( { throttle: 400, callback: (v) => { if (v) { - setFilteredSupplies( - supplies.filter((s) => normalizedCompare(s.name, v)) + const filteredSupplies = supplies.filter((s) => + normalizedCompare(s.name, v) + ); + setSearchedSupplies(filteredSupplies); + } else { + setSearchedSupplies([]); + } + }, + }, + [supplies] + ); + const [searchValue, setSearchValue] = useState(''); + const [, setSearch] = useThrottle( + { + throttle: 400, + callback: (value) => { + if (value) { + const filteredSupplies = supplies.filter((s) => + normalizedCompare(s.name, value) ); - } else setFilteredSupplies(supplies); + setFilteredSupplies(filteredSupplies); + } else { + setFilteredSupplies(supplies); + } }, }, [supplies] @@ -115,6 +138,10 @@ const EditShelterSupply = () => { setFilteredSupplies(supplies); }, [supplies]); + // useEffect(() => { + // setSearch(searchValue); + // }, [searchValue]); + if (loading) return ; return ( @@ -167,13 +194,13 @@ const EditShelterSupply = () => { selecionado

- { - setSearchValue(ev.target.value); - setSearch(ev.target.value); - }} + + setSearchSupplies(value) + } + onSelectItem={(item) => setSearch(item.name)} />
diff --git a/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx b/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx new file mode 100644 index 00000000..f205ce8d --- /dev/null +++ b/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx @@ -0,0 +1,62 @@ +import { Button } from '@/components/ui/button'; +import { Input } from '@/components/ui/input'; +import { IUseSuppliesData } from '@/hooks/useSupplies/types'; +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuGroup, + DropdownMenuItem, + DropdownMenuLabel, + DropdownMenuSeparator, + DropdownMenuTrigger, +} from '@radix-ui/react-dropdown-menu'; +import { Search } from 'lucide-react'; +import { Fragment } from 'react/jsx-runtime'; + +interface ISupplySearchProps { + supplyItems: IUseSuppliesData[]; + limit?: number; + onSearch: (value: string) => void; + onSelectItem: (item: IUseSuppliesData) => void; +} + +export const SupplySearch = ({ + supplyItems, + limit = 10, + onSearch, + onSelectItem, +}: ISupplySearchProps) => { + return ( + +
+ + onSearch(ev.target.value)} + /> +
+ + {supplyItems.length > 0 ? ( +
+ {supplyItems.slice(0, limit).map((item) => ( +
onSelectItem(item)} + > + {item.name} +
+ ))} +
+ Cadastrar novo item +
+
+ ) : null} +
+ ); +}; From bd0dbfceecd9f27da673a709a2cefd9a02bd7806 Mon Sep 17 00:00:00 2001 From: Larissa Pissurno Date: Sun, 19 May 2024 23:57:28 -0300 Subject: [PATCH 06/24] handle add new item --- .../EditShelterSupply/EditShelterSupply.tsx | 18 +++---- .../components/SupplySearch/SupplySearch.tsx | 48 ++++++++++++------- 2 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/pages/EditShelterSupply/EditShelterSupply.tsx b/src/pages/EditShelterSupply/EditShelterSupply.tsx index e2d47a06..65c23673 100644 --- a/src/pages/EditShelterSupply/EditShelterSupply.tsx +++ b/src/pages/EditShelterSupply/EditShelterSupply.tsx @@ -32,20 +32,20 @@ const EditShelterSupply = () => { const [, setSearchSupplies] = useThrottle( { throttle: 400, - callback: (v) => { - if (v) { + callback: (value) => { + if (value) { const filteredSupplies = supplies.filter((s) => - normalizedCompare(s.name, v) + normalizedCompare(s.name, value) ); setSearchedSupplies(filteredSupplies); } else { setSearchedSupplies([]); + setSearch(''); } }, }, [supplies] ); - const [searchValue, setSearchValue] = useState(''); const [, setSearch] = useThrottle( { throttle: 400, @@ -138,10 +138,6 @@ const EditShelterSupply = () => { setFilteredSupplies(supplies); }, [supplies]); - // useEffect(() => { - // setSearch(searchValue); - // }, [searchValue]); - if (loading) return ; return ( @@ -200,7 +196,11 @@ const EditShelterSupply = () => { onSearch={(value) => setSearchSupplies(value) } - onSelectItem={(item) => setSearch(item.name)} + onSelectItem={(item) => { + setSearch(item.name); + setSearchedSupplies([]); + }} + onAddNewItem={() => navigate(`/abrigo/${shelterId}/item/cadastrar`)} />
diff --git a/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx b/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx index f205ce8d..4e7f607e 100644 --- a/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx +++ b/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx @@ -1,16 +1,7 @@ -import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { IUseSuppliesData } from '@/hooks/useSupplies/types'; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuGroup, - DropdownMenuItem, - DropdownMenuLabel, - DropdownMenuSeparator, - DropdownMenuTrigger, -} from '@radix-ui/react-dropdown-menu'; -import { Search } from 'lucide-react'; +import { Search, PlusCircle } from 'lucide-react'; +import { useState } from 'react'; import { Fragment } from 'react/jsx-runtime'; interface ISupplySearchProps { @@ -18,6 +9,7 @@ interface ISupplySearchProps { limit?: number; onSearch: (value: string) => void; onSelectItem: (item: IUseSuppliesData) => void; + onAddNewItem: () => void; } export const SupplySearch = ({ @@ -25,7 +17,24 @@ export const SupplySearch = ({ limit = 10, onSearch, onSelectItem, + onAddNewItem }: ISupplySearchProps) => { + const [searchValue, setSearchValue] = useState(''); + + function onChangeInputHandler(event: React.ChangeEvent) { + setSearchValue(event.target.value); + onSearch(event.target.value); + } + + function onSelectItemHandler(item: IUseSuppliesData) { + setSearchValue(item.name); + onSelectItem(item); + } + + function onAddNewItemHandler() { + onAddNewItem(); + } + return (
onSearch(ev.target.value)} + value={searchValue} + onChange={onChangeInputHandler} />
{supplyItems.length > 0 ? ( -
+
{supplyItems.slice(0, limit).map((item) => (
onSelectItem(item)} + onClick={() => onSelectItemHandler(item)} > {item.name}
))} -
- Cadastrar novo item +
+
+ + Cadastrar novo item +
) : null} From 2fc2bf9257ecc6725de1711926c7a4cfd5871cb0 Mon Sep 17 00:00:00 2001 From: Larissa Pissurno Date: Mon, 20 May 2024 00:02:28 -0300 Subject: [PATCH 07/24] add clear feat --- .../components/SupplySearch/SupplySearch.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx b/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx index 4e7f607e..126e81fd 100644 --- a/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx +++ b/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx @@ -1,6 +1,6 @@ import { Input } from '@/components/ui/input'; import { IUseSuppliesData } from '@/hooks/useSupplies/types'; -import { Search, PlusCircle } from 'lucide-react'; +import { Search, PlusCircle, X } from 'lucide-react'; import { useState } from 'react'; import { Fragment } from 'react/jsx-runtime'; @@ -35,6 +35,11 @@ export const SupplySearch = ({ onAddNewItem(); } + function onClearClickHandler() { + setSearchValue(''); + onSearch(''); + } + return (
+
- {supplyItems.length > 0 ? ( + {!!searchValue ? (
{supplyItems.slice(0, limit).map((item) => (
Date: Mon, 20 May 2024 00:05:33 -0300 Subject: [PATCH 08/24] cleanup --- src/components/ui/command.tsx | 153 ---------------------------------- src/components/ui/popover.tsx | 29 ------- 2 files changed, 182 deletions(-) delete mode 100644 src/components/ui/command.tsx delete mode 100644 src/components/ui/popover.tsx diff --git a/src/components/ui/command.tsx b/src/components/ui/command.tsx deleted file mode 100644 index dd2e876e..00000000 --- a/src/components/ui/command.tsx +++ /dev/null @@ -1,153 +0,0 @@ -import * as React from "react" -import { type DialogProps } from "@radix-ui/react-dialog" -import { Command as CommandPrimitive } from "cmdk" -import { Search } from "lucide-react" - -import { cn } from "@/lib/utils" -import { Dialog, DialogContent } from "@/components/ui/dialog" - -const Command = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) -Command.displayName = CommandPrimitive.displayName - -interface CommandDialogProps extends DialogProps {} - -const CommandDialog = ({ children, ...props }: CommandDialogProps) => { - return ( - - - - {children} - - - - ) -} - -const CommandInput = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( -
- - -
-)) - -CommandInput.displayName = CommandPrimitive.Input.displayName - -const CommandList = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) - -CommandList.displayName = CommandPrimitive.List.displayName - -const CommandEmpty = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->((props, ref) => ( - -)) - -CommandEmpty.displayName = CommandPrimitive.Empty.displayName - -const CommandGroup = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) - -CommandGroup.displayName = CommandPrimitive.Group.displayName - -const CommandSeparator = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) -CommandSeparator.displayName = CommandPrimitive.Separator.displayName - -const CommandItem = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) - -CommandItem.displayName = CommandPrimitive.Item.displayName - -const CommandShortcut = ({ - className, - ...props -}: React.HTMLAttributes) => { - return ( - - ) -} -CommandShortcut.displayName = "CommandShortcut" - -export { - Command, - CommandDialog, - CommandInput, - CommandList, - CommandEmpty, - CommandGroup, - CommandItem, - CommandShortcut, - CommandSeparator, -} diff --git a/src/components/ui/popover.tsx b/src/components/ui/popover.tsx deleted file mode 100644 index bbba7e0e..00000000 --- a/src/components/ui/popover.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import * as React from "react" -import * as PopoverPrimitive from "@radix-ui/react-popover" - -import { cn } from "@/lib/utils" - -const Popover = PopoverPrimitive.Root - -const PopoverTrigger = PopoverPrimitive.Trigger - -const PopoverContent = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( - - - -)) -PopoverContent.displayName = PopoverPrimitive.Content.displayName - -export { Popover, PopoverTrigger, PopoverContent } From 7aa1e550f9ffdd4017499f9048579055d89332db Mon Sep 17 00:00:00 2001 From: Larissa Pissurno Date: Mon, 20 May 2024 00:10:27 -0300 Subject: [PATCH 09/24] cleanup --- package-lock.json | 52 ----------------------------------------------- package.json | 10 ++++----- 2 files changed, 4 insertions(+), 58 deletions(-) diff --git a/package-lock.json b/package-lock.json index 06f7d6a0..33731021 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,6 @@ "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", "@radix-ui/react-label": "^2.0.2", - "@radix-ui/react-popover": "^1.0.7", "@radix-ui/react-radio-group": "^1.1.3", "@radix-ui/react-select": "^2.0.0", "@radix-ui/react-separator": "^1.0.3", @@ -23,7 +22,6 @@ "axios": "^1.6.8", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", - "cmdk": "^1.0.0", "date-fns": "^3.6.0", "formik": "^2.4.6", "lucide-react": "^0.378.0", @@ -1599,43 +1597,6 @@ } } }, - "node_modules/@radix-ui/react-popover": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/@radix-ui/react-popover/-/react-popover-1.0.7.tgz", - "integrity": "sha512-shtvVnlsxT6faMnK/a7n0wptwBD23xc1Z5mdrtKLwVEfsEMXodS0r5s0/g5P0hX//EKYZS2sxUjqfzlg52ZSnQ==", - "dependencies": { - "@babel/runtime": "^7.13.10", - "@radix-ui/primitive": "1.0.1", - "@radix-ui/react-compose-refs": "1.0.1", - "@radix-ui/react-context": "1.0.1", - "@radix-ui/react-dismissable-layer": "1.0.5", - "@radix-ui/react-focus-guards": "1.0.1", - "@radix-ui/react-focus-scope": "1.0.4", - "@radix-ui/react-id": "1.0.1", - "@radix-ui/react-popper": "1.1.3", - "@radix-ui/react-portal": "1.0.4", - "@radix-ui/react-presence": "1.0.1", - "@radix-ui/react-primitive": "1.0.3", - "@radix-ui/react-slot": "1.0.2", - "@radix-ui/react-use-controllable-state": "1.0.1", - "aria-hidden": "^1.1.1", - "react-remove-scroll": "2.5.5" - }, - "peerDependencies": { - "@types/react": "*", - "@types/react-dom": "*", - "react": "^16.8 || ^17.0 || ^18.0", - "react-dom": "^16.8 || ^17.0 || ^18.0" - }, - "peerDependenciesMeta": { - "@types/react": { - "optional": true - }, - "@types/react-dom": { - "optional": true - } - } - }, "node_modules/@radix-ui/react-popper": { "version": "1.1.3", "resolved": "https://registry.npmjs.org/@radix-ui/react-popper/-/react-popper-1.1.3.tgz", @@ -3031,19 +2992,6 @@ "node": ">=6" } }, - "node_modules/cmdk": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/cmdk/-/cmdk-1.0.0.tgz", - "integrity": "sha512-gDzVf0a09TvoJ5jnuPvygTB77+XdOSwEmJ88L6XPFPlv7T3RxbP9jgenfylrAMD0+Le1aO0nVjQUzl2g+vjz5Q==", - "dependencies": { - "@radix-ui/react-dialog": "1.0.5", - "@radix-ui/react-primitive": "1.0.3" - }, - "peerDependencies": { - "react": "^18.0.0", - "react-dom": "^18.0.0" - } - }, "node_modules/color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", diff --git a/package.json b/package.json index a2cd15f5..ac95b4c2 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,6 @@ "@radix-ui/react-checkbox": "^1.0.4", "@radix-ui/react-dialog": "^1.0.5", "@radix-ui/react-label": "^2.0.2", - "@radix-ui/react-popover": "^1.0.7", "@radix-ui/react-radio-group": "^1.1.3", "@radix-ui/react-select": "^2.0.0", "@radix-ui/react-separator": "^1.0.3", @@ -25,17 +24,16 @@ "axios": "^1.6.8", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", - "cmdk": "^1.0.0", "date-fns": "^3.6.0", "formik": "^2.4.6", "lucide-react": "^0.378.0", "qs": "^6.12.1", - "react": "^18.2.0", "react-dom": "^18.2.0", "react-hook-form": "^7.51.4", "react-input-mask": "^2.0.4", "react-router-dom": "^6.23.0", "react-select": "^5.8.0", + "react": "^18.2.0", "tailwind-merge": "^2.3.0", "tailwindcss-animate": "^1.0.7", "yup": "^1.4.0" @@ -43,19 +41,19 @@ "devDependencies": { "@types/node": "^20.12.8", "@types/qs": "^6.9.15", - "@types/react": "^18.2.66", "@types/react-dom": "^18.2.22", "@types/react-input-mask": "^3.0.5", + "@types/react": "^18.2.66", "@typescript-eslint/eslint-plugin": "^7.2.0", "@typescript-eslint/parser": "^7.2.0", "@vitejs/plugin-react": "^4.2.1", "autoprefixer": "^10.4.19", - "eslint": "^8.57.0", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.4.6", + "eslint": "^8.57.0", "postcss": "^8.4.38", "tailwindcss": "^3.4.3", "typescript": "^5.2.2", "vite": "^5.2.0" } -} +} \ No newline at end of file From 5424ce2d9cf324d1389b38d85493bd70709ac0af Mon Sep 17 00:00:00 2001 From: Larissa Pissurno Date: Mon, 20 May 2024 00:11:03 -0300 Subject: [PATCH 10/24] cleanup --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ac95b4c2..29dd3ef1 100644 --- a/package.json +++ b/package.json @@ -56,4 +56,4 @@ "typescript": "^5.2.2", "vite": "^5.2.0" } -} \ No newline at end of file +} From 567102020bf7d0508d4a5b0eb267d986d5406eaf Mon Sep 17 00:00:00 2001 From: Larissa Pissurno Date: Mon, 20 May 2024 00:18:54 -0300 Subject: [PATCH 11/24] fix imports --- src/pages/EditShelterSupply/EditShelterSupply.tsx | 3 +-- .../components/SupplySearch/SupplySearch.tsx | 9 +-------- .../EditShelterSupply/components/SupplySearch/index.ts | 3 +++ .../EditShelterSupply/components/SupplySearch/types.ts | 9 +++++++++ src/pages/EditShelterSupply/components/index.ts | 3 ++- 5 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 src/pages/EditShelterSupply/components/SupplySearch/index.ts create mode 100644 src/pages/EditShelterSupply/components/SupplySearch/types.ts diff --git a/src/pages/EditShelterSupply/EditShelterSupply.tsx b/src/pages/EditShelterSupply/EditShelterSupply.tsx index 65c23673..69b7b1e4 100644 --- a/src/pages/EditShelterSupply/EditShelterSupply.tsx +++ b/src/pages/EditShelterSupply/EditShelterSupply.tsx @@ -6,7 +6,7 @@ import { DialogSelector, Header, LoadingScreen, TextField } from '@/components'; import { Button } from '@/components/ui/button'; import { useShelter, useSupplies, useThrottle } from '@/hooks'; import { group, normalizedCompare } from '@/lib/utils'; -import { SupplyRow } from './components'; +import { SupplyRow, SupplySearch } from './components'; import { IDialogSelectorProps } from '@/components/DialogSelector/types'; import { ISupplyRowItemProps } from './components/SupplyRow/types'; import { ShelterSupplyServices } from '@/service'; @@ -15,7 +15,6 @@ import { SupplyPriority } from '@/service/supply/types'; import { IUseShelterDataSupply } from '@/hooks/useShelter/types'; import { clearCache } from '@/api/cache'; import { IUseSuppliesData } from '@/hooks/useSupplies/types'; -import { SupplySearch } from './components/SupplySearch/SupplySearch'; const EditShelterSupply = () => { const navigate = useNavigate(); diff --git a/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx b/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx index 126e81fd..7f9fb798 100644 --- a/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx +++ b/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx @@ -3,14 +3,7 @@ import { IUseSuppliesData } from '@/hooks/useSupplies/types'; import { Search, PlusCircle, X } from 'lucide-react'; import { useState } from 'react'; import { Fragment } from 'react/jsx-runtime'; - -interface ISupplySearchProps { - supplyItems: IUseSuppliesData[]; - limit?: number; - onSearch: (value: string) => void; - onSelectItem: (item: IUseSuppliesData) => void; - onAddNewItem: () => void; -} +import {ISupplySearchProps} from './types'; export const SupplySearch = ({ supplyItems, diff --git a/src/pages/EditShelterSupply/components/SupplySearch/index.ts b/src/pages/EditShelterSupply/components/SupplySearch/index.ts new file mode 100644 index 00000000..77d5b6cb --- /dev/null +++ b/src/pages/EditShelterSupply/components/SupplySearch/index.ts @@ -0,0 +1,3 @@ +import { SupplySearch } from './SupplySearch'; + +export { SupplySearch }; diff --git a/src/pages/EditShelterSupply/components/SupplySearch/types.ts b/src/pages/EditShelterSupply/components/SupplySearch/types.ts new file mode 100644 index 00000000..c91a92f6 --- /dev/null +++ b/src/pages/EditShelterSupply/components/SupplySearch/types.ts @@ -0,0 +1,9 @@ +import { IUseSuppliesData } from "@/hooks/useSupplies/types"; + +export interface ISupplySearchProps { + supplyItems: IUseSuppliesData[]; + limit?: number; + onSearch: (value: string) => void; + onSelectItem: (item: IUseSuppliesData) => void; + onAddNewItem: () => void; +} \ No newline at end of file diff --git a/src/pages/EditShelterSupply/components/index.ts b/src/pages/EditShelterSupply/components/index.ts index 53a42ef8..10b36121 100644 --- a/src/pages/EditShelterSupply/components/index.ts +++ b/src/pages/EditShelterSupply/components/index.ts @@ -1,4 +1,5 @@ import { SupplyRow } from './SupplyRow'; import { SupplyRowInfo } from './SupplyRowInfo'; +import { SupplySearch } from './SupplySearch'; -export { SupplyRowInfo, SupplyRow }; +export { SupplyRowInfo, SupplyRow, SupplySearch }; From dbb4c6c45447a3d8bc528d1ecfee3986adb50988 Mon Sep 17 00:00:00 2001 From: Larissa Pissurno Date: Mon, 20 May 2024 00:30:23 -0300 Subject: [PATCH 12/24] fix: new item keeps on when item selected --- src/pages/EditShelterSupply/EditShelterSupply.tsx | 3 ++- .../components/SupplySearch/SupplySearch.tsx | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/pages/EditShelterSupply/EditShelterSupply.tsx b/src/pages/EditShelterSupply/EditShelterSupply.tsx index 69b7b1e4..7409cf1d 100644 --- a/src/pages/EditShelterSupply/EditShelterSupply.tsx +++ b/src/pages/EditShelterSupply/EditShelterSupply.tsx @@ -30,7 +30,7 @@ const EditShelterSupply = () => { ); const [, setSearchSupplies] = useThrottle( { - throttle: 400, + throttle: 200, callback: (value) => { if (value) { const filteredSupplies = supplies.filter((s) => @@ -45,6 +45,7 @@ const EditShelterSupply = () => { }, [supplies] ); + const [, setSearch] = useThrottle( { throttle: 400, diff --git a/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx b/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx index 7f9fb798..3e27cab3 100644 --- a/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx +++ b/src/pages/EditShelterSupply/components/SupplySearch/SupplySearch.tsx @@ -13,6 +13,7 @@ export const SupplySearch = ({ onAddNewItem }: ISupplySearchProps) => { const [searchValue, setSearchValue] = useState(''); + const [selectedItem, setSelectedItem] = useState(null); function onChangeInputHandler(event: React.ChangeEvent) { setSearchValue(event.target.value); @@ -21,14 +22,17 @@ export const SupplySearch = ({ function onSelectItemHandler(item: IUseSuppliesData) { setSearchValue(item.name); + setSelectedItem(item); onSelectItem(item); } function onAddNewItemHandler() { + setSelectedItem(null); onAddNewItem(); } function onClearClickHandler() { + setSelectedItem(null); setSearchValue(''); onSearch(''); } @@ -50,7 +54,7 @@ export const SupplySearch = ({
- {!!searchValue ? ( + {!!searchValue && !selectedItem ? (
{supplyItems.slice(0, limit).map((item) => (
Date: Mon, 20 May 2024 00:56:43 -0300 Subject: [PATCH 13/24] update text --- src/pages/EditShelterSupply/EditShelterSupply.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/EditShelterSupply/EditShelterSupply.tsx b/src/pages/EditShelterSupply/EditShelterSupply.tsx index 7409cf1d..07e2e3e5 100644 --- a/src/pages/EditShelterSupply/EditShelterSupply.tsx +++ b/src/pages/EditShelterSupply/EditShelterSupply.tsx @@ -186,8 +186,7 @@ const EditShelterSupply = () => {
Editar itens do abrigo

- Para cada item da lista abaixo, informe a disponibilidade no abrigo - selecionado + Antes de adicionar um novo item, confira na busca abaixo se ele já não foi cadastrado.

Date: Mon, 20 May 2024 11:30:43 -0300 Subject: [PATCH 14/24] add text above list --- src/pages/EditShelterSupply/EditShelterSupply.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pages/EditShelterSupply/EditShelterSupply.tsx b/src/pages/EditShelterSupply/EditShelterSupply.tsx index 07e2e3e5..c16f6f71 100644 --- a/src/pages/EditShelterSupply/EditShelterSupply.tsx +++ b/src/pages/EditShelterSupply/EditShelterSupply.tsx @@ -202,6 +202,10 @@ const EditShelterSupply = () => { onAddNewItem={() => navigate(`/abrigo/${shelterId}/item/cadastrar`)} />
+ +

+ Para cada item da lista abaixo, informe a disponibilidade no abrigo selecionado. +

{Object.entries(supplyGroups).map(([key, values], idx) => { const items: ISupplyRowItemProps[] = values From ba795f4486d708de2ccbf69db08aaaf90052e653 Mon Sep 17 00:00:00 2001 From: Larissa Pissurno Date: Mon, 20 May 2024 11:53:55 -0300 Subject: [PATCH 15/24] add initial filter to show only stored supplies --- .../EditShelterSupply/EditShelterSupply.tsx | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/pages/EditShelterSupply/EditShelterSupply.tsx b/src/pages/EditShelterSupply/EditShelterSupply.tsx index c16f6f71..26ad1146 100644 --- a/src/pages/EditShelterSupply/EditShelterSupply.tsx +++ b/src/pages/EditShelterSupply/EditShelterSupply.tsx @@ -28,6 +28,13 @@ const EditShelterSupply = () => { const [searchedSupplies, setSearchedSupplies] = useState( [] ); + const shelterSupplyData = useMemo(() => { + return (shelter?.shelterSupplies ?? []).reduce( + (prev, current) => ({ ...prev, [current.supply.id]: current }), + {} as Record + ); + }, [shelter?.shelterSupplies]); + const [, setSearchSupplies] = useThrottle( { throttle: 200, @@ -56,11 +63,12 @@ const EditShelterSupply = () => { ); setFilteredSupplies(filteredSupplies); } else { - setFilteredSupplies(supplies); + const storedSupplies = supplies.filter((s) => !!shelterSupplyData[s.id]); + setFilteredSupplies(storedSupplies); } }, }, - [supplies] + [supplies, shelterSupplyData] ); const [modalOpened, setModalOpened] = useState(false); const [loadingSave, setLoadingSave] = useState(false); @@ -68,12 +76,7 @@ const EditShelterSupply = () => { IDialogSelectorProps, 'value' | 'onSave' | 'quantity' > | null>(); - const shelterSupplyData = useMemo(() => { - return (shelter?.shelterSupplies ?? []).reduce( - (prev, current) => ({ ...prev, [current.supply.id]: current }), - {} as Record - ); - }, [shelter?.shelterSupplies]); + const supplyGroups = useMemo( () => group(filteredSupplies ?? [], 'supplyCategory.name'), @@ -135,8 +138,9 @@ const EditShelterSupply = () => { ); useEffect(() => { - setFilteredSupplies(supplies); - }, [supplies]); + const storedSupplies = supplies.filter((s) => !!shelterSupplyData[s.id]); + setFilteredSupplies(storedSupplies); + }, [supplies, shelterSupplyData]); if (loading) return ; From 286c867168628707ae7fc47acd6b487a3a1201a9 Mon Sep 17 00:00:00 2001 From: Giovanni Bassi Date: Mon, 20 May 2024 19:13:16 -0300 Subject: [PATCH 16/24] Add contributing --- CONTRIBUTING.md | 127 ++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 55 ++++++++------------- 2 files changed, 146 insertions(+), 36 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..9d44effa --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,127 @@ +# Contribuindo + +Você pode contribuir com o projeto de diversas formas, implementando uma +funcionalidade nova, corrigindo um bug, procurando bugs, revisando pull +requests, entre outras. +Para se inteirar do projeto, entre no +[Discord](https://discord.gg/vjZS6BQXvM) e participe das discussões. + +## 🤝 Contribuindo com atividades que não são de código + +O projeto precisa de ajuda em diversas frentes diferentes como: QA, produto, +design e gestão. Entre no servidor do Discord onde há canais específicos para +essas atividades. + +Se você encontrou um bug, vá nas +[issues](https://github.com/SOS-RS/frontend/issues) +do projeto e reporte-o lá. Verifique antes se já não existe um bug aberto para o +problema que quer relatar, usando a busca. O mesmo vale para novas +funcionalidades. + +O restante deste documento focará nas contribuições de código. + +## ✅ Escolhendo qual será sua contribuição de código + +Verifique no [projeto do Github](https://github.com/orgs/SOS-RS/projects/1) +quais funcionalidades ainda não foram implementadas e já estão prontas para +serem desenvolvidas, elas estarão na coluna "Disponível pra dev". Lá há itens de +backend e frontend, então atente-se para qual você gostaria de participar. + +Após escolher o item que quer trabalhar, faça um comentário no issue informando +que quer contribuir para sua entrega. Uma pessoa que administra o repositório +marcará você como a pessoa responsável por aquele issue, e marcará o item como +"Em desenvolvimento". + +A partir daí você já pode trabalhar no item que escolheu. + +Você também pode mandar a contribuição diretamente sem avisar, mas corre o +risco de alguém solicitar para trabalhar no item e entregá-lo junto ou antes de +você, desperdiçando assim esforços. Somente faça isso se a correção for bem rápida e pontual para +evitar o desperdício. + +⚠️ **Importante**: Itens de alta prioridade precisam ser entregues o mais rápido possível, +idealmente em até dois dias. Verifique se tem tempo livre suficiente para se +dedicar a um item de urgência, a fim de evitar segurar o item por tempo demais +de forma desnecessária. + +## 🚀 Configuração Inicial Local + +1. Faça um fork do repositório para o seu usuário (uma boa ideia é usar um nome mais descritivo do que `frontend`, como `sos-rs-frontend`). +2. Clone o repositório (troque `` na url abaixo pelo seu usuário): + + ```bash + git clone https://github.com//sos-rs-frontend.git + ``` + +3. Instale as dependências: + + ```bash + npm install + ``` + +4. Inicie o servidor: + + ```bash + npm run dev + ``` + + O app estará disponível em . + +5. Inicie o servidor de backend. Veja as instruções no seu + [documento de contribuição](https://github.com/SOS-RS/backend/blob/develop/CONTRIBUTING.md). + +## 💻 Codificando e enviando + +1. Faça suas alterações. +2. Rode o lint com `npm run lint`. +3. Crie um branch com o git `git checkout -b nomedobranch`. +4. Faça um commit com `git commit`. +5. Faça um push para o seu repositório com `git push`. +6. [Sincronize seu repositório](#-sincronizando). +7. [Abra um pull request](https://docs.github.com/pt/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request). + Não deixe de informar, no seu pull request, qual a issue que está fechando. + Idealmente coloque um comentário no PR que já fechará a issue, como + `fixes #xxxx` ou `closes #xxxx` (onde `xxxx` é o número do issue). Veja + [como isso funciona](https://docs.github.com/pt/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests). +8. Acompanhe a revisão do PR. Algumas verificações automáticas serão feitas (o + Github Actions rodará o build do Vite, por exemplo). Se uma delas falhar, corrija-a, a + revisão humana só começa quando estas checagem estão passando. Após abrir o + PR uma pessoa que administra o projeto pode pedir revisões e alterações. + Busque respondê-las o mais rápido possível para que o PR possa ser integrado. + +## 🔄 Sincronizando + +Você vai precisar, de tempos em tempos, sincronizar a branch `develop` do +seu repositório. Você pode usar o botão `Sync fork` do Github +(veja [os docs](https://docs.github.com/pt/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork)). +Ou você pode fazer manualmente, o que te permite fazer a sincronização sem depender do Github: + +1. Antes de mais nada, se estiver no meio de uma contribuição, verifique que já commitou + tudo que tinha pra commitar, e então faça checkout do branch `develop`: + + ```bash + git checkout develop + ``` + +2. Adicione o repositório oficial como remoto com nome `upstream` (só necessário na primeira vez): + + ```bash + git remote add upstream https://github.com/SOS-RS/frontend.git + ``` + +3. Faça pull do branch `develop`: + + ```bash + git pull upstream develop + ``` + +4. Se estiver no meio de uma contribuição, faça um rebase no branch `develop` + (substitua `` pelo nome do seu branch): + + ```bash + git checkout + git rebase develop + ``` + + Após o rebase, é importante rodar novamente a aplicação e verificar se tudo + continua funcionando. diff --git a/README.md b/README.md index 6d7e165b..0be3ac88 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,22 @@ -# README +# 🌊 Frontend para App de Ajuda em Enchentes 🌊 Este projeto é o frontend de um aplicativo destinado a auxiliar na organização e distribuição de suprimentos, além de coordenar voluntários durante os alagamentos no Rio Grande do Sul. A aplicação visa conectar pessoas afetadas pelas enchentes com recursos essenciais e voluntários dispostos a ajudar. +O objetivo deste aplicativo é facilitar uma resposta rápida e eficiente em situações de emergência causadas por enchentes, promovendo a colaboração e o apoio mútuo entre a comunidade e organizações de ajuda. + +Se você quiser discutir ideias, problemas ou contribuições, sinta-se à vontade para se juntar ao nosso servidor do +Discord [aqui](https://discord.gg/vjZS6BQXvM). + ## Acesso à Aplicação [SOS Rio Grande do Sul](https://sos-rs.com/) -[Discord](https://discord.gg/eJTuannsd6) -## Sobre o Projeto +## 🤝 Contribuição -O objetivo deste aplicativo é facilitar uma resposta rápida e eficiente em situações de emergência causadas por enchentes, promovendo a colaboração e o apoio mútuo entre a comunidade e organizações de ajuda. +Contribuições são muito bem-vindas! Se deseja ajudar, veja o +[documento de contribuição](./CONTRIBUTING.md). + +Agradecemos o seu interesse e apoio. Juntos, podemos fazer uma diferença significativa para as vítimas das enchentes no Rio Grande do Sul! ## Tecnologias Utilizadas @@ -20,36 +27,12 @@ Este frontend foi desenvolvido utilizando as seguintes tecnologias: - [**Tailwind CSS**](https://tailwindcss.com/docs/installation): Framework CSS baseado em classes utilitárias. - [**shadcn/ui**](https://ui.shadcn.com/docs): Coleção de componentes reutilizáveis, baseado em Tailwind. -Para executar o frontend do aplicativo em seu ambiente local, siga os passos abaixo: - -1. Clone o repositório: - ``` - git clone https://github.com/SOS-RS/frontend - ``` -2. Entre no diretório do projeto: - ``` - cd frontend - ``` -3. Instale as dependências: - ``` - npm install - ``` -4. Inicie o servidor de desenvolvimento: - ``` - npm run dev - ``` - O app estará disponível em `http://localhost:5173`. - -## Contribuindo - -Contribuições são muito bem-vindas! Se você tem interesse em ajudar a melhorar o app, por favor: - -1. Faça um fork do repositório. -2. Crie uma branch para sua feature (`git checkout -b feature/MinhaFeature`). -3. Faça seus commits (`git commit -m 'Adicionando uma nova feature'`). -4. Faça push para a branch (`git push origin feature/MinhaFeature`). -5. Abra um Pull Request. - ---- +## Licença -Agradecemos o seu interesse e apoio. Juntos, podemos fazer uma diferença significativa para as vítimas das enchentes no Rio Grande do Sul! +Este código está licenciado usando a +[licença MIT](./LICENSE). + +## Contribuidores + +Os contribuidores são voluntários, e podem ser encontrados +[na página de contribuidores](https://github.com/SOS-RS/frontend/graphs/contributors). From 97fb4431c26cb4b9ebf76f2989e293f6116bae9b Mon Sep 17 00:00:00 2001 From: Larissa Pissurno Date: Tue, 21 May 2024 10:56:24 -0300 Subject: [PATCH 17/24] remove unused import --- src/pages/EditShelterSupply/EditShelterSupply.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/EditShelterSupply/EditShelterSupply.tsx b/src/pages/EditShelterSupply/EditShelterSupply.tsx index 26ad1146..c5d804d7 100644 --- a/src/pages/EditShelterSupply/EditShelterSupply.tsx +++ b/src/pages/EditShelterSupply/EditShelterSupply.tsx @@ -2,7 +2,7 @@ import { ChevronLeft } from 'lucide-react'; import { useNavigate, useParams } from 'react-router-dom'; import { Fragment, useCallback, useEffect, useMemo, useState } from 'react'; -import { DialogSelector, Header, LoadingScreen, TextField } from '@/components'; +import { DialogSelector, Header, LoadingScreen } from '@/components'; import { Button } from '@/components/ui/button'; import { useShelter, useSupplies, useThrottle } from '@/hooks'; import { group, normalizedCompare } from '@/lib/utils'; From 180a9147d91bf4ca0a1b9796dc10efeec5cee9ce Mon Sep 17 00:00:00 2001 From: rayanerocha07 Date: Tue, 21 May 2024 11:29:50 -0300 Subject: [PATCH 18/24] Resolves #284 --- src/components/ui/badge-variants.tsx | 23 +++++++++++++ src/components/ui/badge.tsx | 31 ++++------------- src/components/ui/button-variants.tsx | 32 +++++++++++++++++ src/components/ui/button.tsx | 34 ++----------------- src/hooks/useAuthRoles/MappedRoles.tsx | 10 ++++++ src/hooks/useAuthRoles/SessionContext.tsx | 11 ++++++ src/hooks/useAuthRoles/useAuthRoles.tsx | 21 ++++-------- src/hooks/useShelters/useShelters.tsx | 2 +- src/lib/utils.ts | 2 +- .../ShelterListItem/ShelterListItem.tsx | 2 +- 10 files changed, 94 insertions(+), 74 deletions(-) create mode 100644 src/components/ui/badge-variants.tsx create mode 100644 src/components/ui/button-variants.tsx create mode 100644 src/hooks/useAuthRoles/MappedRoles.tsx create mode 100644 src/hooks/useAuthRoles/SessionContext.tsx diff --git a/src/components/ui/badge-variants.tsx b/src/components/ui/badge-variants.tsx new file mode 100644 index 00000000..bee7c587 --- /dev/null +++ b/src/components/ui/badge-variants.tsx @@ -0,0 +1,23 @@ +import { cva } from "class-variance-authority"; + +const badgeVariants = cva( + "inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", + { + variants: { + variant: { + default: + "border-transparent bg-primary text-primary-foreground hover:bg-primary/80", + secondary: + "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", + destructive: + "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80", + outline: "text-foreground", + }, + }, + defaultVariants: { + variant: "default", + }, + } +); + +export { badgeVariants }; diff --git a/src/components/ui/badge.tsx b/src/components/ui/badge.tsx index f000e3ef..aeaf8fb0 100644 --- a/src/components/ui/badge.tsx +++ b/src/components/ui/badge.tsx @@ -1,27 +1,8 @@ -import * as React from "react" -import { cva, type VariantProps } from "class-variance-authority" +import * as React from "react"; +import { type VariantProps } from "class-variance-authority"; -import { cn } from "@/lib/utils" - -const badgeVariants = cva( - "inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", - { - variants: { - variant: { - default: - "border-transparent bg-primary text-primary-foreground hover:bg-primary/80", - secondary: - "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", - destructive: - "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80", - outline: "text-foreground", - }, - }, - defaultVariants: { - variant: "default", - }, - } -) +import { cn } from "@/lib/utils"; +import { badgeVariants } from "./badge-variants"; export interface BadgeProps extends React.HTMLAttributes, @@ -30,7 +11,7 @@ export interface BadgeProps function Badge({ className, variant, ...props }: BadgeProps) { return (
- ) + ); } -export { Badge, badgeVariants } +export { Badge }; diff --git a/src/components/ui/button-variants.tsx b/src/components/ui/button-variants.tsx new file mode 100644 index 00000000..d997ddee --- /dev/null +++ b/src/components/ui/button-variants.tsx @@ -0,0 +1,32 @@ +import { cva } from 'class-variance-authority'; + +const buttonVariants = cva( + 'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50', + { + variants: { + variant: { + default: 'bg-primary text-primary-foreground hover:bg-primary/90', + destructive: + 'bg-destructive text-destructive-foreground hover:bg-destructive/90', + outline: + 'border border-input bg-background hover:bg-accent hover:text-accent-foreground', + secondary: + 'bg-secondary text-secondary-foreground hover:bg-secondary/80', + ghost: 'hover:bg-accent hover:text-accent-foreground', + link: 'text-primary underline-offset-4 hover:underline', + }, + size: { + default: 'h-10 px-4 py-2', + sm: 'h-9 rounded-md px-3', + lg: 'h-11 rounded-md px-8', + icon: 'h-10 w-10', + }, + }, + defaultVariants: { + variant: 'default', + size: 'default', + }, + } +); + +export { buttonVariants }; diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx index 58bd1541..70280b11 100644 --- a/src/components/ui/button.tsx +++ b/src/components/ui/button.tsx @@ -1,38 +1,10 @@ import * as React from 'react'; import { Slot } from '@radix-ui/react-slot'; -import { cva, type VariantProps } from 'class-variance-authority'; +import { type VariantProps } from 'class-variance-authority'; import { cn } from '@/lib/utils'; import { Loader } from 'lucide-react'; - -const buttonVariants = cva( - 'inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50', - { - variants: { - variant: { - default: 'bg-primary text-primary-foreground hover:bg-primary/90', - destructive: - 'bg-destructive text-destructive-foreground hover:bg-destructive/90', - outline: - 'border border-input bg-background hover:bg-accent hover:text-accent-foreground', - secondary: - 'bg-secondary text-secondary-foreground hover:bg-secondary/80', - ghost: 'hover:bg-accent hover:text-accent-foreground', - link: 'text-primary underline-offset-4 hover:underline', - }, - size: { - default: 'h-10 px-4 py-2', - sm: 'h-9 rounded-md px-3', - lg: 'h-11 rounded-md px-8', - icon: 'h-10 w-10', - }, - }, - defaultVariants: { - variant: 'default', - size: 'default', - }, - } -); +import { buttonVariants } from './button-variants'; export interface ButtonProps extends React.ButtonHTMLAttributes, @@ -70,4 +42,4 @@ const Button = React.forwardRef( ); Button.displayName = 'Button'; -export { Button, buttonVariants }; +export { Button }; diff --git a/src/hooks/useAuthRoles/MappedRoles.tsx b/src/hooks/useAuthRoles/MappedRoles.tsx new file mode 100644 index 00000000..a16f925a --- /dev/null +++ b/src/hooks/useAuthRoles/MappedRoles.tsx @@ -0,0 +1,10 @@ +import { AccessLevel } from '@/service/sessions/types'; + +const MappedRoles: Record = { + Admin: ['Admin'], + DistributionCenter: ['Admin', 'DistributionCenter'], + Staff: ['Admin', 'Staff'], + User: ['Admin', 'Staff', 'DistributionCenter', 'User'], +}; + +export default MappedRoles; diff --git a/src/hooks/useAuthRoles/SessionContext.tsx b/src/hooks/useAuthRoles/SessionContext.tsx new file mode 100644 index 00000000..b6b6866f --- /dev/null +++ b/src/hooks/useAuthRoles/SessionContext.tsx @@ -0,0 +1,11 @@ +import { createContext } from 'react'; +import { ISession } from '@/service/sessions/types'; + +type SessionContextType = { + session: ISession | null; +}; + +const SessionContext = createContext({ session: null }); + +export { SessionContext }; export type { SessionContextType }; + diff --git a/src/hooks/useAuthRoles/useAuthRoles.tsx b/src/hooks/useAuthRoles/useAuthRoles.tsx index f3e7d45a..4047752a 100644 --- a/src/hooks/useAuthRoles/useAuthRoles.tsx +++ b/src/hooks/useAuthRoles/useAuthRoles.tsx @@ -1,25 +1,16 @@ import { useContext } from 'react'; - -import { SessionContext } from '@/contexts'; +import { SessionContext } from '@/contexts/SessionContext'; +import MappedRoles from '@/hooks/useAuthRoles/MappedRoles'; import { AccessLevel } from '@/service/sessions/types'; -const MappedRoles: Record = { - Admin: ['Admin'], - DistributionCenter: ['Admin', 'DistributionCenter'], - Staff: ['Admin', 'Staff'], - User: ['Admin', 'Staff', 'DistributionCenter', 'User'], -}; - -const useAuthRoles = (...roles: AccessLevel[]) => { +const useAuthRoles = (...roles: AccessLevel[]): boolean => { const { session } = useContext(SessionContext); - if ( - !session || - !roles.some((role) => MappedRoles[role].includes(session.accessLevel)) - ) + if (!session) { return false; + } - return true; + return roles.some((role) => MappedRoles[role].includes(session.accessLevel)); }; export { useAuthRoles }; diff --git a/src/hooks/useShelters/useShelters.tsx b/src/hooks/useShelters/useShelters.tsx index a13a3c82..f6959800 100644 --- a/src/hooks/useShelters/useShelters.tsx +++ b/src/hooks/useShelters/useShelters.tsx @@ -53,7 +53,7 @@ const useShelters = (options: IUseShelterOptions = {}) => { if (!append) setLoading(false); }); }, - [] + [cache] ); useEffect(() => { diff --git a/src/lib/utils.ts b/src/lib/utils.ts index dc8981ac..fcdd3245 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -72,7 +72,7 @@ function getAvailabilityProps(props: { } const priorityOptions: Record = { - [SupplyPriority.Urgent]: 'Necessita urgente', + [SupplyPriority.Urgent]: 'Precisa com urgência', [SupplyPriority.Needing]: 'Precisa', [SupplyPriority.Remaining]: 'Disponível para doação', [SupplyPriority.NotNeeded]: 'Não preciso', diff --git a/src/pages/Home/components/ShelterListItem/ShelterListItem.tsx b/src/pages/Home/components/ShelterListItem/ShelterListItem.tsx index 391585e5..4bcdd86a 100644 --- a/src/pages/Home/components/ShelterListItem/ShelterListItem.tsx +++ b/src/pages/Home/components/ShelterListItem/ShelterListItem.tsx @@ -100,7 +100,7 @@ const ShelterListItem = (props: IShelterListItemProps) => { tags={tags.NeedVolunteers.map(getChipProps)} /> Date: Wed, 22 May 2024 10:03:04 -0300 Subject: [PATCH 19/24] review --- src/lib/utils.ts | 2 +- src/pages/EditShelterSupply/EditShelterSupply.tsx | 2 +- src/pages/Home/components/Filter/Filter.tsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index fcdd3245..cf0e858a 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -36,7 +36,7 @@ const colorStatusPriority = (priority: SupplyPriority) => { * deprecated */ function nameStatusPriority(priority: SupplyPriority) { - if (priority === SupplyPriority.Needing) return 'Precisa urgentimente'; + if (priority === SupplyPriority.Needing) return 'Precisa com urgência'; if (priority === SupplyPriority.Urgent) return 'Precisa'; if (priority === SupplyPriority.NotNeeded) return 'Não preciso'; if (priority === SupplyPriority.Remaining) return 'Disponível para doação'; diff --git a/src/pages/EditShelterSupply/EditShelterSupply.tsx b/src/pages/EditShelterSupply/EditShelterSupply.tsx index c7729e6e..47b1dfcf 100644 --- a/src/pages/EditShelterSupply/EditShelterSupply.tsx +++ b/src/pages/EditShelterSupply/EditShelterSupply.tsx @@ -126,7 +126,7 @@ const EditShelterSupply = () => { title="Escolha a prioridade do item" options={[ { - label: 'Precisa urgente', + label: 'Precisa com urgência', value: `${SupplyPriority.Urgent}`, }, { diff --git a/src/pages/Home/components/Filter/Filter.tsx b/src/pages/Home/components/Filter/Filter.tsx index 344fddd6..59caf9eb 100644 --- a/src/pages/Home/components/Filter/Filter.tsx +++ b/src/pages/Home/components/Filter/Filter.tsx @@ -176,7 +176,7 @@ const Filter = (props: IFilterProps) => {

Busca avançada

- Você pode buscar pelo item que os abrigos precisam urgentemente + Você pode buscar pelo item que os abrigos precisam com urgência de doação ou por itens que os abrigos tem disponibilidade para doar.

From afbbbf07166f1d61724f6e9dcb071170f8e138ac Mon Sep 17 00:00:00 2001 From: rayanerocha07 Date: Wed, 22 May 2024 10:08:48 -0300 Subject: [PATCH 20/24] removes unusued session context --- src/hooks/useAuthRoles/SessionContext.tsx | 11 ----------- src/hooks/useAuthRoles/useAuthRoles.tsx | 13 ++++++++----- 2 files changed, 8 insertions(+), 16 deletions(-) delete mode 100644 src/hooks/useAuthRoles/SessionContext.tsx diff --git a/src/hooks/useAuthRoles/SessionContext.tsx b/src/hooks/useAuthRoles/SessionContext.tsx deleted file mode 100644 index b6b6866f..00000000 --- a/src/hooks/useAuthRoles/SessionContext.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import { createContext } from 'react'; -import { ISession } from '@/service/sessions/types'; - -type SessionContextType = { - session: ISession | null; -}; - -const SessionContext = createContext({ session: null }); - -export { SessionContext }; export type { SessionContextType }; - diff --git a/src/hooks/useAuthRoles/useAuthRoles.tsx b/src/hooks/useAuthRoles/useAuthRoles.tsx index 4047752a..1fd40ffa 100644 --- a/src/hooks/useAuthRoles/useAuthRoles.tsx +++ b/src/hooks/useAuthRoles/useAuthRoles.tsx @@ -1,16 +1,19 @@ import { useContext } from 'react'; -import { SessionContext } from '@/contexts/SessionContext'; + +import { SessionContext } from '@/contexts'; import MappedRoles from '@/hooks/useAuthRoles/MappedRoles'; import { AccessLevel } from '@/service/sessions/types'; -const useAuthRoles = (...roles: AccessLevel[]): boolean => { +const useAuthRoles = (...roles: AccessLevel[]) => { const { session } = useContext(SessionContext); - if (!session) { + if ( + !session || + !roles.some((role) => MappedRoles[role].includes(session.accessLevel)) + ) return false; - } - return roles.some((role) => MappedRoles[role].includes(session.accessLevel)); + return true; }; export { useAuthRoles }; From 703aa9b90c979232d9f684449cacb0a1c95eb308 Mon Sep 17 00:00:00 2001 From: rayanerocha07 Date: Wed, 22 May 2024 10:13:44 -0300 Subject: [PATCH 21/24] finishing --- src/lib/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index cf0e858a..68853c20 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -36,8 +36,8 @@ const colorStatusPriority = (priority: SupplyPriority) => { * deprecated */ function nameStatusPriority(priority: SupplyPriority) { - if (priority === SupplyPriority.Needing) return 'Precisa com urgência'; - if (priority === SupplyPriority.Urgent) return 'Precisa'; + if (priority === SupplyPriority.Urgent) return 'Precisa com urgência'; + if (priority === SupplyPriority.Needing) return 'Precisa'; if (priority === SupplyPriority.NotNeeded) return 'Não preciso'; if (priority === SupplyPriority.Remaining) return 'Disponível para doação'; } From dc0bb643d591384c6258a91fbb8d9f105aa5f908 Mon Sep 17 00:00:00 2001 From: rayanerocha07 Date: Wed, 22 May 2024 10:49:52 -0300 Subject: [PATCH 22/24] removes unusued functions --- src/lib/utils.ts | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 68853c20..c12c1b59 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -12,36 +12,6 @@ function cn(...inputs: ClassValue[]) { return twMerge(clsx(inputs)); } -/** - * deprecated - */ -function variantStatusPriority(priority: SupplyPriority) { - if (priority === SupplyPriority.Needing) return 'danger'; - if (priority === SupplyPriority.Urgent) return 'warn'; - if (priority === SupplyPriority.NotNeeded) return 'alert'; - if (priority === SupplyPriority.Remaining) return 'success'; -} - -/** - * deprecated - */ -const colorStatusPriority = (priority: SupplyPriority) => { - if (priority === SupplyPriority.Needing) return 'bg-[#f69f9d]'; - if (priority === SupplyPriority.Urgent) return 'bg-[#f8b993]'; - if (priority === SupplyPriority.NotNeeded) return 'bg-[#f9cf8d]'; - if (priority === SupplyPriority.Remaining) return 'bg-[#63bc43]'; -}; - -/** - * deprecated - */ -function nameStatusPriority(priority: SupplyPriority) { - if (priority === SupplyPriority.Urgent) return 'Precisa com urgência'; - if (priority === SupplyPriority.Needing) return 'Precisa'; - if (priority === SupplyPriority.NotNeeded) return 'Não preciso'; - if (priority === SupplyPriority.Remaining) return 'Disponível para doação'; -} - function getAvailabilityProps(props: { capacity?: number | null; shelteredPeople?: number | null; @@ -185,9 +155,6 @@ export { getAvailabilityProps, group, getSupplyPriorityProps, - variantStatusPriority, - colorStatusPriority, - nameStatusPriority, priorityOptions, groupShelterSuppliesByTag, removeDuplicatesByField, From fd5fefe0dd5281d0b33f42b3f723f98ea64e67b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Geraldo=20D=2E=20F?= Date: Thu, 23 May 2024 17:59:25 -0300 Subject: [PATCH 23/24] feat: added more contributors to about me page (#292) --- src/pages/AboutUs/AboutUs.tsx | 101 +++++++++++++++++++--------------- src/pages/AboutUs/types.ts | 4 ++ 2 files changed, 61 insertions(+), 44 deletions(-) create mode 100644 src/pages/AboutUs/types.ts diff --git a/src/pages/AboutUs/AboutUs.tsx b/src/pages/AboutUs/AboutUs.tsx index f66ef145..efeffa9d 100644 --- a/src/pages/AboutUs/AboutUs.tsx +++ b/src/pages/AboutUs/AboutUs.tsx @@ -1,4 +1,4 @@ -import { useMemo } from 'react'; +import { Fragment, useMemo } from 'react'; import { HandHeart, Home, LifeBuoy, Loader, Users } from 'lucide-react'; import { BurgerMenu, Header } from '@/components'; @@ -7,6 +7,7 @@ import { frontItems } from './frontItems'; import { useGithubContributors } from '@/hooks'; import WithTooltip from '@/components/ui/with-tooltip'; import { removeDuplicatesByField } from '@/lib/utils'; +import { IAboutUsPerson } from './types'; const AboutUs = () => { const { data: frontendContributors, loading: loadingFrontendContributors } = @@ -14,6 +15,45 @@ const AboutUs = () => { const { data: backendContributors, loading: loadingBackendContributors } = useGithubContributors('sos-rs', 'backend'); + const persons: IAboutUsPerson[] = [ + { + name: 'Klaus Riffel', + link: 'https://www.linkedin.com/in/klaus-riffel-69441928/', + }, + { + name: 'Rhuam Estevam', + link: 'https://www.linkedin.com/in/rhuam/', + }, + { + name: 'José Fagundes', + link: 'https://www.linkedin.com/in/jos%C3%A9-fagundes/', + }, + { + name: 'Manoel Júnior', + link: 'https://www.linkedin.com/in/manoelfpjunior/', + }, + { + name: 'Vinicius Arantes', + link: 'https://www.linkedin.com/in/viniciusrnt/', + }, + { + name: 'Thiago Marins', + link: 'https://www.linkedin.com/in/thiago-dable', + }, + { + name: 'Gabriel Mancuso', + link: 'https://www.linkedin.com/in/luizgabrielmancuso/', + }, + { + name: 'Max Riffel', + link: 'https://www.linkedin.com/in/max-riffel-07a134a1/', + }, + { + name: 'Kiwi Bertola', + link: 'https://www.linkedin.com/in/kiwi-bertola-10079073/', + }, + ]; + const loading = useMemo( () => loadingBackendContributors || loadingFrontendContributors, [loadingBackendContributors, loadingFrontendContributors] @@ -43,50 +83,23 @@ const AboutUs = () => {

Iniciado no domingo (04/05) e concluído na segunda (05/05), após 18 - horas seguidas de desenvolvimento, nosso webapp SOS RS - - , idealizado e desenvolvido por{' '} - - Klaus Riffel - - ,{' '} - - Rhuam Estevam - - ,{' '} - - José Fagundes - - ,{' '} - - Manoel Júnior - {' '} + horas seguidas de desenvolvimento, nosso webapp SOS RS 🛟, + idealizado e desenvolvido por{' '} + {persons.slice(0, -1).map((p, idx) => ( + + + {p.name} + + {', '} + + ))}{' '} e{' '} - Vinicius Arantes + {persons.at(-1)?.name} , atingiu resultados verdadeiramente inspiradores.

@@ -95,8 +108,8 @@ const AboutUs = () => { seu modelo colaborativo. Alcançamos rapidamente o nível de todas as outras iniciativas de gestão de demanda combinadas e lançamos nossa comunidade open source, recebendo uma enxurrada de contribuições: - nosso projeto alcançou 400 estrelas no GitHub e foi{' '} - forkeado mais de 150 vezes! + nosso projeto alcançou 600 estrelas no GitHub e foi{' '} + forkeado mais de 350 vezes!

Nossos parceiros @@ -109,7 +122,7 @@ const AboutUs = () => { } topLabel="mais de" - centerLabel="500" + centerLabel="800" bottomLabel="abrigos atendidos" className="flex-1" /> @@ -123,7 +136,7 @@ const AboutUs = () => { } topLabel="mais de" - centerLabel="40.000" + centerLabel="55.000" bottomLabel="pessoas beneficiadas desde o lançamento" className="w-full" /> diff --git a/src/pages/AboutUs/types.ts b/src/pages/AboutUs/types.ts new file mode 100644 index 00000000..029d6d52 --- /dev/null +++ b/src/pages/AboutUs/types.ts @@ -0,0 +1,4 @@ +export interface IAboutUsPerson { + name: string; + link: string; +} From d208bf16707b8d6819ddb395b6a1850e5287f45c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Geraldo=20D=2E=20F?= Date: Thu, 23 May 2024 17:59:51 -0300 Subject: [PATCH 24/24] feat: added hmac and obfuscate api module (#294) --- .env.example | 3 +- .github/workflows/deploy.yml | 1 + .github/workflows/dev.yml | 1 + .github/workflows/staging.yml | 1 + package-lock.json | 731 ++++++++++++++++++++++++++++++++++ package.json | 9 +- src/api/api.ts | 11 + src/api/hmac.ts | 26 ++ vite.config.ts | 48 ++- 9 files changed, 822 insertions(+), 9 deletions(-) create mode 100644 src/api/hmac.ts diff --git a/.env.example b/.env.example index 119819a6..fa8ac5ee 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ -VITE_API_URL=http://localhost:4000 \ No newline at end of file +VITE_API_URL=http://localhost:4000 +VITE_HMAC_SECRET_KEY= \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5375d85e..ab4b3a6c 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -22,6 +22,7 @@ jobs: run: | touch .env echo VITE_API_URL=${{ secrets.VITE_API_URL }} >> .env + echo VITE_HMAC_SECRET_KEY=${{ secrets.VITE_HMAC_SECRET_KEY }} >> .env cat .env - run: npm run build diff --git a/.github/workflows/dev.yml b/.github/workflows/dev.yml index be5fa7a8..a0c70d84 100644 --- a/.github/workflows/dev.yml +++ b/.github/workflows/dev.yml @@ -22,6 +22,7 @@ jobs: run: | touch .env echo VITE_API_URL=${{ secrets.DEV_VITE_API_URL }} >> .env + echo VITE_HMAC_SECRET_KEY=${{ secrets.VITE_HMAC_SECRET_KEY }} >> .env cat .env - run: npm run build diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml index b9ad33de..044858fd 100644 --- a/.github/workflows/staging.yml +++ b/.github/workflows/staging.yml @@ -22,6 +22,7 @@ jobs: run: | touch .env echo VITE_API_URL=${{ secrets.STG_VITE_API_URL }} >> .env + echo VITE_HMAC_SECRET_KEY=${{ secrets.VITE_HMAC_SECRET_KEY }} >> .env cat .env - run: npm run build diff --git a/package-lock.json b/package-lock.json index 33731021..7aa87d0b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "axios": "^1.6.8", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", + "crypto-js": "^4.2.0", "date-fns": "^3.6.0", "formik": "^2.4.6", "lucide-react": "^0.378.0", @@ -37,6 +38,7 @@ "yup": "^1.4.0" }, "devDependencies": { + "@types/crypto-js": "^4.2.2", "@types/node": "^20.12.8", "@types/qs": "^6.9.15", "@types/react": "^18.2.66", @@ -49,6 +51,7 @@ "eslint": "^8.57.0", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.4.6", + "javascript-obfuscator": "^4.1.0", "postcss": "^8.4.38", "tailwindcss": "^3.4.3", "typescript": "^5.2.2", @@ -1160,6 +1163,94 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, + "node_modules/@javascript-obfuscator/escodegen": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@javascript-obfuscator/escodegen/-/escodegen-2.3.0.tgz", + "integrity": "sha512-QVXwMIKqYMl3KwtTirYIA6gOCiJ0ZDtptXqAv/8KWLG9uQU2fZqTVy7a/A5RvcoZhbDoFfveTxuGxJ5ibzQtkw==", + "dev": true, + "dependencies": { + "@javascript-obfuscator/estraverse": "^5.3.0", + "esprima": "^4.0.1", + "esutils": "^2.0.2", + "optionator": "^0.8.1" + }, + "engines": { + "node": ">=6.0" + }, + "optionalDependencies": { + "source-map": "~0.6.1" + } + }, + "node_modules/@javascript-obfuscator/escodegen/node_modules/levn": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.3.0.tgz", + "integrity": "sha512-0OO4y2iOHix2W6ujICbKIaEQXvFQHue65vUG3pb5EUomzPI90z9hsA1VsO/dbIIpC53J8gxM9Q4Oho0jrCM/yA==", + "dev": true, + "dependencies": { + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/@javascript-obfuscator/escodegen/node_modules/optionator": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz", + "integrity": "sha512-+IW9pACdk3XWmmTXG8m3upGUJst5XRGzxMRjXzAuJ1XnIFNvfhjjIuYkDvysnPQ7qzqVzLt78BCruntqRhWQbA==", + "dev": true, + "dependencies": { + "deep-is": "~0.1.3", + "fast-levenshtein": "~2.0.6", + "levn": "~0.3.0", + "prelude-ls": "~1.1.2", + "type-check": "~0.3.2", + "word-wrap": "~1.2.3" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/@javascript-obfuscator/escodegen/node_modules/prelude-ls": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz", + "integrity": "sha512-ESF23V4SKG6lVSGZgYNpbsiaAkdab6ZgOxe52p7+Kid3W3u3bxR4Vfd/o21dmN7jSt0IwgZ4v5MUd26FEtXE9w==", + "dev": true, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/@javascript-obfuscator/escodegen/node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "optional": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/@javascript-obfuscator/escodegen/node_modules/type-check": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.3.2.tgz", + "integrity": "sha512-ZCmOJdvOWDBYJlzAoFkC+Q0+bUyEOS1ltgp1MGU03fqHG+dbi9tBFU2Rd9QKiDZFAYrhPh2JUf7rZRIuHRKtOg==", + "dev": true, + "dependencies": { + "prelude-ls": "~1.1.2" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/@javascript-obfuscator/estraverse": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/@javascript-obfuscator/estraverse/-/estraverse-5.4.0.tgz", + "integrity": "sha512-CZFX7UZVN9VopGbjTx4UXaXsi9ewoM1buL0kY7j1ftYdSs7p2spv9opxFjHlQ/QGTgh4UqufYqJJ0WKLml7b6w==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, "node_modules/@jridgewell/gen-mapping": { "version": "0.3.5", "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", @@ -2325,6 +2416,12 @@ "@babel/types": "^7.20.7" } }, + "node_modules/@types/crypto-js": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/@types/crypto-js/-/crypto-js-4.2.2.tgz", + "integrity": "sha512-sDOLlVbHhXpAUAL0YHDUUwDZf3iN4Bwi4W6a0W0b+QcAezUbRtH4FVb+9J4h+XFPW7l/gQ9F8qC7P+Ec4k8QVQ==", + "dev": true + }, "node_modules/@types/estree": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", @@ -2346,6 +2443,12 @@ "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "dev": true }, + "node_modules/@types/minimatch": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/@types/minimatch/-/minimatch-3.0.5.tgz", + "integrity": "sha512-Klz949h02Gz2uZCMGwDUSDS1YBlTdDDgbWHi+81l29tQALUtvz4rAYi5uoVhE5Lagoq6DeqAUlbrHvW/mXDgdQ==", + "dev": true + }, "node_modules/@types/node": { "version": "20.12.10", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.10.tgz", @@ -2412,6 +2515,12 @@ "integrity": "sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==", "dev": true }, + "node_modules/@types/validator": { + "version": "13.11.10", + "resolved": "https://registry.npmjs.org/@types/validator/-/validator-13.11.10.tgz", + "integrity": "sha512-e2PNXoXLr6Z+dbfx5zSh9TRlXJrELycxiaXznp4S5+D2M3b9bqJEitNHA5923jhnB2zzFiZHa2f0SI1HoIahpg==", + "dev": true + }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "7.8.0", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.8.0.tgz", @@ -2722,6 +2831,15 @@ "node": ">=10" } }, + "node_modules/array-differ": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/array-differ/-/array-differ-3.0.0.tgz", + "integrity": "sha512-THtfYS6KtME/yIAhKjZ2ul7XI96lQGHRputJQHO80LAWQnuGP4iCIN8vdMRboGbIEYBwU33q8Tch1os2+X0kMg==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/array-union": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/array-union/-/array-union-2.1.0.tgz", @@ -2731,6 +2849,27 @@ "node": ">=8" } }, + "node_modules/arrify": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/arrify/-/arrify-2.0.1.tgz", + "integrity": "sha512-3duEwti880xqi4eAMN8AyR4a0ByT90zoYdLlevfrvU43vb0YZwZVfxOgxWrLXXXpyugL0hNZc9G6BiB5B3nUug==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/assert": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/assert/-/assert-2.0.0.tgz", + "integrity": "sha512-se5Cd+js9dXJnu6Ag2JFc00t+HmHOen+8Q+L7O9zI0PqQXr20uk2J0XQqMxZEeo5U50o8Nvmmx7dZrl+Ufr35A==", + "dev": true, + "dependencies": { + "es6-object-assign": "^1.1.0", + "is-nan": "^1.2.1", + "object-is": "^1.0.1", + "util": "^0.12.0" + } + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -2773,6 +2912,21 @@ "postcss": "^8.1.0" } }, + "node_modules/available-typed-arrays": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", + "integrity": "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==", + "dev": true, + "dependencies": { + "possible-typed-array-names": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/axios": { "version": "1.6.8", "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz", @@ -2864,6 +3018,12 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, + "node_modules/buffer-from": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz", + "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", + "dev": true + }, "node_modules/call-bind": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", @@ -2931,6 +3091,30 @@ "node": ">=4" } }, + "node_modules/chance": { + "version": "1.1.9", + "resolved": "https://registry.npmjs.org/chance/-/chance-1.1.9.tgz", + "integrity": "sha512-TfxnA/DcZXRTA4OekA2zL9GH8qscbbl6X0ZqU4tXhGveVY/mXWvEQLt5GwZcYXTEyEFflVtj+pG8nc8EwSm1RQ==", + "dev": true + }, + "node_modules/char-regex": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/char-regex/-/char-regex-1.0.2.tgz", + "integrity": "sha512-kWWXztvZ5SBQV+eRgKFeh8q5sLuZY2+8WUIzlxWVTg+oGwY14qylx1KbKzHd8P6ZYkAg0xyIDU9JMHhyJMZ1jw==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/charenc": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz", + "integrity": "sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA==", + "dev": true, + "engines": { + "node": "*" + } + }, "node_modules/chokidar": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz", @@ -2965,6 +3149,17 @@ "node": ">= 6" } }, + "node_modules/class-validator": { + "version": "0.14.0", + "resolved": "https://registry.npmjs.org/class-validator/-/class-validator-0.14.0.tgz", + "integrity": "sha512-ct3ltplN8I9fOwUd8GrP8UQixwff129BkEtuWDKL5W45cQuLd19xqmTLu5ge78YDm/fdje6FMt0hGOhl0lii3A==", + "dev": true, + "dependencies": { + "@types/validator": "^13.7.10", + "libphonenumber-js": "^1.10.14", + "validator": "^13.7.0" + } + }, "node_modules/class-variance-authority": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/class-variance-authority/-/class-variance-authority-0.7.0.tgz", @@ -3072,6 +3267,20 @@ "node": ">= 8" } }, + "node_modules/crypt": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz", + "integrity": "sha512-mCxBlsHFYh9C+HVpiEacem8FEBnMXgU9gy4zmNC+SXAZNB/1idgp/aulFJ4FgCi7GPEVbfyng092GqL2k2rmow==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/crypto-js": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", + "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" + }, "node_modules/cssesc": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz", @@ -3144,6 +3353,23 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/define-properties": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", + "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", + "dev": true, + "dependencies": { + "define-data-property": "^1.0.1", + "has-property-descriptors": "^1.0.0", + "object-keys": "^1.1.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -3243,6 +3469,12 @@ "node": ">= 0.4" } }, + "node_modules/es6-object-assign": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz", + "integrity": "sha512-MEl9uirslVwqQU369iHNWZXsI8yaZYGg/D65aOgZkeyFJwHYSxilf7rQzXKI7DdDuBPrBXbfk3sl9hJhmd5AUw==", + "dev": true + }, "node_modules/esbuild": { "version": "0.20.2", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.20.2.tgz", @@ -3550,6 +3782,19 @@ "url": "https://opencollective.com/eslint" } }, + "node_modules/esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true, + "bin": { + "esparse": "bin/esparse.js", + "esvalidate": "bin/esvalidate.js" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/esquery": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.5.0.tgz", @@ -3727,6 +3972,15 @@ } } }, + "node_modules/for-each": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", + "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", + "dev": true, + "dependencies": { + "is-callable": "^1.1.3" + } + }, "node_modules/foreground-child": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", @@ -3994,6 +4248,21 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "dev": true, + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/hasown": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", @@ -4070,6 +4339,28 @@ "loose-envify": "^1.0.0" } }, + "node_modules/inversify": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/inversify/-/inversify-6.0.1.tgz", + "integrity": "sha512-B3ex30927698TJENHR++8FfEaJGqoWOgI6ZY5Ht/nLUsFCwHn6akbwtnUAPCgUepAnTpe2qHxhDNjoKLyz6rgQ==", + "dev": true + }, + "node_modules/is-arguments": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", + "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", @@ -4086,6 +4377,24 @@ "node": ">=8" } }, + "node_modules/is-buffer": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz", + "integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==", + "dev": true + }, + "node_modules/is-callable": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", + "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-core-module": { "version": "2.13.1", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", @@ -4113,6 +4422,21 @@ "node": ">=8" } }, + "node_modules/is-generator-function": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz", + "integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==", + "dev": true, + "dependencies": { + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", @@ -4124,6 +4448,22 @@ "node": ">=0.10.0" } }, + "node_modules/is-nan": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/is-nan/-/is-nan-1.3.2.tgz", + "integrity": "sha512-E+zBKpQ2t6MEo1VsonYmluk9NxGrbzpeeLC2xIViuO2EjU2xsXsBPwTr3Ykv9l08UYEVEdWeRZNouaZqF6RN0w==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", @@ -4141,6 +4481,21 @@ "node": ">=8" } }, + "node_modules/is-typed-array": { + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.13.tgz", + "integrity": "sha512-uZ25/bUAlUY5fR4OKT4rZQEBrzQWYV9ZJYGGsUmEJ6thodVJ1HX64ePQ6Z0qPWP+m+Uq6e9UugrE38jeYsDSMw==", + "dev": true, + "dependencies": { + "which-typed-array": "^1.1.14" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -4163,6 +4518,167 @@ "@pkgjs/parseargs": "^0.11.0" } }, + "node_modules/javascript-obfuscator": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/javascript-obfuscator/-/javascript-obfuscator-4.1.0.tgz", + "integrity": "sha512-ckC0VFKQ0/sFtLH9apW/ZLfsP8LuZqZhVEM4VTJ5KLzyLaodW6C1lTU8808eboDmddKyvd2uyRx5bzc0Me0GYg==", + "dev": true, + "hasInstallScript": true, + "dependencies": { + "@javascript-obfuscator/escodegen": "2.3.0", + "@javascript-obfuscator/estraverse": "5.4.0", + "acorn": "8.8.2", + "assert": "2.0.0", + "chalk": "4.1.2", + "chance": "1.1.9", + "class-validator": "0.14.0", + "commander": "10.0.0", + "eslint-scope": "7.1.1", + "eslint-visitor-keys": "3.3.0", + "fast-deep-equal": "3.1.3", + "inversify": "6.0.1", + "js-string-escape": "1.0.1", + "md5": "2.3.0", + "mkdirp": "2.1.3", + "multimatch": "5.0.0", + "opencollective-postinstall": "2.0.3", + "process": "0.11.10", + "reflect-metadata": "0.1.13", + "source-map-support": "0.5.21", + "string-template": "1.0.0", + "stringz": "2.1.0", + "tslib": "2.5.0" + }, + "bin": { + "javascript-obfuscator": "bin/javascript-obfuscator" + }, + "engines": { + "node": "^12.22.0 || ^14.0.0 || ^16.0.0 || ^17.0.0 || >=18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/javascript-obfuscator" + } + }, + "node_modules/javascript-obfuscator/node_modules/acorn": { + "version": "8.8.2", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz", + "integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/javascript-obfuscator/node_modules/ansi-styles": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", + "dev": true, + "dependencies": { + "color-convert": "^2.0.1" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/chalk/ansi-styles?sponsor=1" + } + }, + "node_modules/javascript-obfuscator/node_modules/chalk": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", + "dev": true, + "dependencies": { + "ansi-styles": "^4.1.0", + "supports-color": "^7.1.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, + "node_modules/javascript-obfuscator/node_modules/color-convert": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz", + "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==", + "dev": true, + "dependencies": { + "color-name": "~1.1.4" + }, + "engines": { + "node": ">=7.0.0" + } + }, + "node_modules/javascript-obfuscator/node_modules/color-name": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", + "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", + "dev": true + }, + "node_modules/javascript-obfuscator/node_modules/commander": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.0.tgz", + "integrity": "sha512-zS5PnTI22FIRM6ylNW8G4Ap0IEOyk62fhLSD0+uHRT9McRCLGpkVNvao4bjimpK/GShynyQkFFxHhwMcETmduA==", + "dev": true, + "engines": { + "node": ">=14" + } + }, + "node_modules/javascript-obfuscator/node_modules/eslint-scope": { + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.1.1.tgz", + "integrity": "sha512-QKQM/UXpIiHcLqJ5AOyIW7XZmzjkzQXYE54n1++wb0u9V/abW3l9uQnxX8Z5Xd18xyKIMTUAyQ0k1e8pz6LUrw==", + "dev": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/javascript-obfuscator/node_modules/eslint-visitor-keys": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", + "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/javascript-obfuscator/node_modules/has-flag": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", + "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/javascript-obfuscator/node_modules/supports-color": { + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", + "dev": true, + "dependencies": { + "has-flag": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/javascript-obfuscator/node_modules/tslib": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.5.0.tgz", + "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==", + "dev": true + }, "node_modules/jiti": { "version": "1.21.0", "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.0.tgz", @@ -4171,6 +4687,15 @@ "jiti": "bin/jiti.js" } }, + "node_modules/js-string-escape": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/js-string-escape/-/js-string-escape-1.0.1.tgz", + "integrity": "sha512-Smw4xcfIQ5LVjAOuJCvN/zIodzA/BBSsluuoSykP+lUvScIi4U6RJLfwHet5cxFnCswUjISV8oAXaqaJDY3chg==", + "dev": true, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -4257,6 +4782,12 @@ "node": ">= 0.8.0" } }, + "node_modules/libphonenumber-js": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/libphonenumber-js/-/libphonenumber-js-1.11.1.tgz", + "integrity": "sha512-Wze1LPwcnzvcKGcRHFGFECTaLzxOtujwpf924difr5zniyYv1C2PiW0419qDR7m8lKDxsImu5mwxFuXhXpjmvw==", + "dev": true + }, "node_modules/lilconfig": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/lilconfig/-/lilconfig-2.1.0.tgz", @@ -4329,6 +4860,17 @@ "react": "^16.5.1 || ^17.0.0 || ^18.0.0" } }, + "node_modules/md5": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/md5/-/md5-2.3.0.tgz", + "integrity": "sha512-T1GITYmFaKuO91vxyoQMFETst+O71VUPEU3ze5GNzDm0OWdP8v1ziTaAEPUr/3kLsY3Sftgz242A1SetQiDL7g==", + "dev": true, + "dependencies": { + "charenc": "0.0.2", + "crypt": "0.0.2", + "is-buffer": "~1.1.6" + } + }, "node_modules/memoize-one": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-6.0.0.tgz", @@ -4395,12 +4937,68 @@ "node": ">=16 || 14 >=14.17" } }, + "node_modules/mkdirp": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-2.1.3.tgz", + "integrity": "sha512-sjAkg21peAG9HS+Dkx7hlG9Ztx7HLeKnvB3NQRcu/mltCVmvkF0pisbiTSfDVYTT86XEfZrTUosLdZLStquZUw==", + "dev": true, + "bin": { + "mkdirp": "dist/cjs/src/bin.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, + "node_modules/multimatch": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/multimatch/-/multimatch-5.0.0.tgz", + "integrity": "sha512-ypMKuglUrZUD99Tk2bUQ+xNQj43lPEfAeX2o9cTteAmShXy2VHDJpuwu1o0xqoKCt9jLVAvwyFKdLTPXKAfJyA==", + "dev": true, + "dependencies": { + "@types/minimatch": "^3.0.3", + "array-differ": "^3.0.0", + "array-union": "^2.1.0", + "arrify": "^2.0.1", + "minimatch": "^3.0.4" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/multimatch/node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dev": true, + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/multimatch/node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dev": true, + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, "node_modules/mz": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz", @@ -4481,6 +5079,31 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/object-is": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.6.tgz", + "integrity": "sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.7", + "define-properties": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", + "dev": true, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -4490,6 +5113,15 @@ "wrappy": "1" } }, + "node_modules/opencollective-postinstall": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.3.tgz", + "integrity": "sha512-8AV/sCtuzUeTo8gQK5qDZzARrulB3egtLzFgteqB2tcT4Mw7B8Kt7JcDHmltjz6FOAHsvTevk70gZEbhM4ZS9Q==", + "dev": true, + "bin": { + "opencollective-postinstall": "index.js" + } + }, "node_modules/optionator": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.4.tgz", @@ -4659,6 +5291,15 @@ "node": ">= 6" } }, + "node_modules/possible-typed-array-names": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", + "integrity": "sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==", + "dev": true, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/postcss": { "version": "8.4.38", "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.38.tgz", @@ -4809,6 +5450,15 @@ "node": ">= 0.8.0" } }, + "node_modules/process": { + "version": "0.11.10", + "resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz", + "integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==", + "dev": true, + "engines": { + "node": ">= 0.6.0" + } + }, "node_modules/prop-types": { "version": "15.8.1", "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", @@ -5092,6 +5742,12 @@ "node": ">=8.10.0" } }, + "node_modules/reflect-metadata": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", + "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==", + "dev": true + }, "node_modules/regenerator-runtime": { "version": "0.14.1", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", @@ -5310,6 +5966,31 @@ "node": ">=0.10.0" } }, + "node_modules/source-map-support": { + "version": "0.5.21", + "resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.5.21.tgz", + "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", + "dev": true, + "dependencies": { + "buffer-from": "^1.0.0", + "source-map": "^0.6.0" + } + }, + "node_modules/source-map-support/node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/string-template": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/string-template/-/string-template-1.0.0.tgz", + "integrity": "sha512-SLqR3GBUXuoPP5MmYtD7ompvXiG87QjT6lzOszyXjTM86Uu7At7vNnt2xgyTLq5o9T4IxTYFyGxcULqpsmsfdg==", + "dev": true + }, "node_modules/string-width": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz", @@ -5370,6 +6051,15 @@ "url": "https://github.com/chalk/strip-ansi?sponsor=1" } }, + "node_modules/stringz": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/stringz/-/stringz-2.1.0.tgz", + "integrity": "sha512-KlywLT+MZ+v0IRepfMxRtnSvDCMc3nR1qqCs3m/qIbSOWkNZYT8XHQA31rS3TnKp0c5xjZu3M4GY/2aRKSi/6A==", + "dev": true, + "dependencies": { + "char-regex": "^1.0.2" + } + }, "node_modules/strip-ansi": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", @@ -5746,11 +6436,33 @@ } } }, + "node_modules/util": { + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz", + "integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==", + "dev": true, + "dependencies": { + "inherits": "^2.0.3", + "is-arguments": "^1.0.4", + "is-generator-function": "^1.0.7", + "is-typed-array": "^1.1.3", + "which-typed-array": "^1.1.2" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, + "node_modules/validator": { + "version": "13.12.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-13.12.0.tgz", + "integrity": "sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==", + "dev": true, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/vite": { "version": "5.2.11", "resolved": "https://registry.npmjs.org/vite/-/vite-5.2.11.tgz", @@ -5828,6 +6540,25 @@ "node": ">= 8" } }, + "node_modules/which-typed-array": { + "version": "1.1.15", + "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.15.tgz", + "integrity": "sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA==", + "dev": true, + "dependencies": { + "available-typed-arrays": "^1.0.7", + "call-bind": "^1.0.7", + "for-each": "^0.3.3", + "gopd": "^1.0.1", + "has-tostringtag": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", diff --git a/package.json b/package.json index 29dd3ef1..62a1de6d 100644 --- a/package.json +++ b/package.json @@ -24,33 +24,36 @@ "axios": "^1.6.8", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", + "crypto-js": "^4.2.0", "date-fns": "^3.6.0", "formik": "^2.4.6", "lucide-react": "^0.378.0", "qs": "^6.12.1", + "react": "^18.2.0", "react-dom": "^18.2.0", "react-hook-form": "^7.51.4", "react-input-mask": "^2.0.4", "react-router-dom": "^6.23.0", "react-select": "^5.8.0", - "react": "^18.2.0", "tailwind-merge": "^2.3.0", "tailwindcss-animate": "^1.0.7", "yup": "^1.4.0" }, "devDependencies": { + "@types/crypto-js": "^4.2.2", "@types/node": "^20.12.8", "@types/qs": "^6.9.15", + "@types/react": "^18.2.66", "@types/react-dom": "^18.2.22", "@types/react-input-mask": "^3.0.5", - "@types/react": "^18.2.66", "@typescript-eslint/eslint-plugin": "^7.2.0", "@typescript-eslint/parser": "^7.2.0", "@vitejs/plugin-react": "^4.2.1", "autoprefixer": "^10.4.19", + "eslint": "^8.57.0", "eslint-plugin-react-hooks": "^4.6.0", "eslint-plugin-react-refresh": "^0.4.6", - "eslint": "^8.57.0", + "javascript-obfuscator": "^4.1.0", "postcss": "^8.4.38", "tailwindcss": "^3.4.3", "typescript": "^5.2.2", diff --git a/src/api/api.ts b/src/api/api.ts index 3c975711..9f1c03fd 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -1,5 +1,6 @@ import axios, { AxiosRequestHeaders, InternalAxiosRequestConfig } from 'axios'; import { clearCache, getCacheRequestData, handleCacheResponse } from './cache'; +import { getHmacHeaders } from './hmac'; const api = axios.create({ baseURL: import.meta.env.VITE_API_URL ?? 'http://localhost:4000/', @@ -14,12 +15,22 @@ api.interceptors.request.use((config) => { if (!config.headers) config.headers = {} as AxiosRequestHeaders; handleRequestAuthToken(config); const response = getCacheRequestData(config); + if (response) { config.adapter = () => { return new Promise((resolve) => { resolve({ ...response, config }); }); }; + } else { + const hmacHeaders = getHmacHeaders({ + method: config.method?.toUpperCase(), + url: [config.url, new URLSearchParams(config.params).toString()] + .filter((p) => !!p) + .join('?'), + body: config.data, + }); + Object.assign(config.headers, hmacHeaders); } return config; }); diff --git a/src/api/hmac.ts b/src/api/hmac.ts new file mode 100644 index 00000000..19516e06 --- /dev/null +++ b/src/api/hmac.ts @@ -0,0 +1,26 @@ +import CryptoJS from 'crypto-js'; + +export interface IHmacProps { + method: string; + url: string; + body?: string; +} + +function getHmacHeaders(props: Partial) { + const { method, url, body } = props; + const timestamp = Math.floor(Date.now() / 1000); + + const payload = `${method}:${url}:${timestamp}:${JSON.stringify(body)}`; + + const signature = CryptoJS.HmacSHA256( + payload, + import.meta.env.VITE_HMAC_SECRET_KEY + ).toString(CryptoJS.enc.Hex); + + return { + 'x-hmac-signature': signature, + 'x-hmac-timestamp': `${timestamp}`, + }; +} + +export { getHmacHeaders }; diff --git a/vite.config.ts b/vite.config.ts index cf45b55d..09f48bae 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,12 +1,50 @@ -import path from "path"; -import react from "@vitejs/plugin-react"; -import { defineConfig } from "vite"; +import path from 'path'; +import react from '@vitejs/plugin-react'; +import { defineConfig, Plugin } from 'vite'; +import JavaScriptObfuscator from 'javascript-obfuscator'; + +function obfuscate(includes: string[] = []): Plugin { + return { + name: 'vite-javascript-obfuscator', + apply: 'build', + enforce: 'post', + generateBundle(options, bundle) { + for (const fileName in bundle) { + const chunk = bundle[fileName]; + if ( + chunk.type === 'chunk' && + fileName.endsWith('.js') && + includes.some((f) => fileName.includes(f)) + ) { + const obfuscatedCode = JavaScriptObfuscator.obfuscate(chunk.code, { + compact: true, + numbersToExpressions: true, + stringArrayShuffle: true, + splitStrings: true, + stringArrayThreshold: 1, + }).getObfuscatedCode(); + chunk.code = obfuscatedCode; + } + } + }, + }; +} export default defineConfig({ - plugins: [react()], + plugins: [react(), obfuscate(['api'])], resolve: { alias: { - "@": path.resolve(__dirname, "./src"), + '@': path.resolve(__dirname, './src'), + }, + }, + build: { + rollupOptions: { + output: { + manualChunks: { + vendor: ['react', 'react-dom'], + api: ['./src/api'], + }, + }, }, }, });