From 0d9053f2d7f0a2918d122bd3705722dc91756cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Geraldo=20D=2E=20F?= Date: Wed, 15 May 2024 17:51:25 -0300 Subject: [PATCH] Release/0.0.3 (#187) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [fix] Config readme * wip: loading * Delete yarn.lock * refact: created shelter list view component in home page * Fix: mobile UI has broken for mobile devices (#22) *Fix: mobile UI has broken for mobile devices * fix: remove chip as fixed as no wrap property * chore: add shelter card clickable * chore: remove Fragment component * build: add set sm as max mobile dimension sm: 425px * style: add responsive layout * refactor: filter page * fix: priority * fix: filter parameters * fix: fixed volunteer supply that had been fulfilled displaying on shelter page * fix: improve readability * feat: hidden filter button if filter is empty * feat: cache in axios request * fix: cache search params * feat: cache clean on searchs * wip: donation tags * fix: clean search params * Update README.md [fix] Retirando a seção Funcionalidades e Backlog * fix: donation tags / componentized the urgent supplies section * fix: removed empty shelter tags empty row * feat: full edit shelter and improved interface of pet friendly in shelter page * refact: add live link and tech stack to readme * Fix/develop bugs (#90) * fix: cache bug (invalite cache on create/update operation) * feat: added update many shelter supplies and admin rule * Add license (#81) Closes #65. * fix: app port (#80) * docs: added shadcn/ui reference * fix for volunteer shelter title (#95) * treat contact link as a proper link * simplified href * docs: add discord link on readme * Normalizes search string in supply filter so it ignores accents (#125) * normalized search string to ignore accents * revert removed button * add a copy to clipboard button to PIX and contact info (#124) * add a copy to clipboard button to PIX and contact info * use && operator instead of ternary * Substitui onClick e useNavigate por para melhorar acessibilidade (#128) * replaced navigate in favour of html link and added card hover * fixed lint warnings * fix: change shelter title style (#106) Prevents badge misalignment on very large titles * Add new feature and creating LoadingSkeleton (#115) * Add new feature and creating LoadingSkeleton * fix/add: add favicon and canonical metatag (#136) * fix/add: add favicon and canonical metatag * fix: fixed the path * refactor: changed order of shelters to updated at instead priority sum (#137) * Remove zod dependency (#143) * replaced zod validation with yup * removed zod dependency from package.json * sort dependencies * fixed validation schema variable name * removed .shape() and added .strict() * deleted unused file * Added burger menu to home page (#149) * Implemented Burger menu * commented unused components * feat: Update BurgerMenu to display user's name when logged in * removed comments * implemented login and logout button * Feat/partners (#155) * fix: menu bar with api partners * fix: menu bar with api partners * fix: remove unused session in burguer menu / removed import all icons from lucide and use link icon instead custom icons * [BUG] Botão de Limpar Filtro sumindo após remover input de busca (#147) * fix: clean filter button disappearing after removing search input manually * fix: removing log * Modificação nas telas de abrigos para adicionar cidades (#110) * feat: filter shlters by cities * feat: city on shelter forms, info and list * feat: shelter city quantities on filter * fix: wrong conditional * fix: bug that removing city filter on home doesnt affect the filter * feat: new address fields on shelter forms * feat: useDebouncedValue, useViaCep * feat: adapt useFetch for conditional paths and different response * feat: address fields required and zipCode triggering viaCep * feat: address fields required on update shelter * feat: address fields on shelter details when theres no address field * fix: suggestions(shorthand, optional chaining, separated zipCode, formatted city on list) * feat: sticky footer on filter dialog * fix: reset errors on zipcode search; copy filter change * fix: timeoutId not assigned value; InfoRow copy can copy undefined * Campo de quantidade adicionado quando adicionar suprimento a um abrigo (#46) * feat(shelter-supply): input to add quantity supply * feat(shelter-supply): show quantity supply at Shelter page and EditShelter page * resolve conflict --------- Co-authored-by: Lipe * feat: google analytics * feat: edit shelter supply item quantity (#170) * fix: send address field formatted (#171) * feat: add a template to log bugs/defects (#168) * feat: add a template to log bugs/defects * Feat/privacy terms about us (#169) * feat: privacy policy page * feat: done about us page * fix: removed redundant value check in info row component * fix: ordering the list of items on the shelter edit page (#166) * feat: Melhoria no esquema de cores dos chip's e ajuste de acessibilidade (#162) * feat: new text colors with adjusted light var colors * feat: change chip element tag to span and improve a11y * feat: added update date information to shelter page (#159) * Adding update date to shelter page * (Aditional) Informing when no update date for shelter in main page * feat: ajuste de textos de voluntários e doações (#129) * hotfix: shelter list item broken div tag * Feat/back navigation to home (#177) * feat: added back navigation to home when click in header label * Hotfix/merge bugs (#183) * fix: shelter list item duplicate code after merge * fix: order in filter select menu, filter supplies by category and useSupplies interface * fix: update shelter validation schema and created useAuthRoles hook to reduce complexity of code * fix: conflicts with master branch --------- Co-authored-by: helenapaixao Co-authored-by: Luccas Specht Co-authored-by: MatheusDubin Co-authored-by: danmqs Co-authored-by: Giovanni Bassi <334958+giggio@users.noreply.github.com> Co-authored-by: Felipe Monteiro Co-authored-by: André Ferraz <74271823+decofma@users.noreply.github.com> Co-authored-by: Sombrio Co-authored-by: Filipe Pacheco de Fraga Co-authored-by: Daniel Marques Co-authored-by: Matheus Dubin Da Silveira <46721495+MatheusDubin@users.noreply.github.com> Co-authored-by: Miguel Dalberto <65927539+migueldalberto@users.noreply.github.com> Co-authored-by: Pablo A. Maximo Co-authored-by: Marcos Nascimento <62677231+Marcos-Nacimento@users.noreply.github.com> Co-authored-by: Gilmar José <99229360+g42puts@users.noreply.github.com> Co-authored-by: Kelvin Co-authored-by: Jhonatan David <82552187+jotahdavid@users.noreply.github.com> Co-authored-by: Alexander Scheibler <60936422+alexanderscheibler@users.noreply.github.com> Co-authored-by: Giovani Andrino Carnaval Co-authored-by: Thiago Oliveira <55795035+thdq@users.noreply.github.com> Co-authored-by: Henrique Uhlmann Gobbi Co-authored-by: Janderson Soares <7406406+jandersonsc@users.noreply.github.com> --- .github/ISSUE_TEMPLATE/bug-report.md | 29 + package-lock.json | 11 +- package.json | 9 +- .../Authenticated/Authenticated.tsx | 17 +- src/components/BurgerMenu/BurgerMenu.tsx | 98 ++++ .../BurguerMenuItem/BurguerMenuItem.tsx | 30 ++ .../components/BurguerMenuItem/index.ts | 3 + .../components/BurguerMenuItem/types.ts | 7 + src/components/BurgerMenu/components/index.ts | 3 + src/components/BurgerMenu/index.ts | 3 + .../CardAboutShelter/CardAboutShelter.tsx | 12 +- .../components/InfoRow/InfoRow.tsx | 14 +- src/components/CardAboutShelter/index.ts | 5 +- src/components/CardAboutShelter/utils.ts | 28 + src/components/Chip/Chip.tsx | 6 +- src/components/Chip/types.ts | 1 + .../DialogSelector/DialogSelector.tsx | 47 +- src/components/DialogSelector/types.ts | 3 +- src/components/Header/Header.tsx | 7 +- src/components/SearchInput/SearchInput.tsx | 10 +- src/components/index.ts | 2 + src/components/ui/sheet.tsx | 137 +++++ src/global.css | 8 +- src/hooks/index.ts | 12 + src/hooks/useAuthRoles/index.ts | 3 + src/hooks/useAuthRoles/useAuthRoles.tsx | 25 + src/hooks/useDebouncedValue/index.ts | 3 + .../useDebouncedValue/useDebouncedValue.ts | 27 + src/hooks/useFetch/useFetch.tsx | 15 +- src/hooks/useGithubContributors/index.ts | 3 + src/hooks/useGithubContributors/types.ts | 21 + .../useGithubContributors.tsx | 31 ++ src/hooks/usePaginatedQuery/paths.ts | 1 + src/hooks/usePartners/index.ts | 3 + src/hooks/usePartners/types.ts | 7 + src/hooks/usePartners/usePartners.tsx | 11 + src/hooks/useShelter/types.ts | 6 + src/hooks/useShelterCities/index.ts | 3 + src/hooks/useShelterCities/types.ts | 4 + .../useShelterCities/useShelterCities.ts | 9 + src/hooks/useShelters/types.ts | 6 + src/hooks/useSupplies/types.ts | 12 + src/hooks/useSupplies/useSupplies.tsx | 4 +- src/hooks/useViaCep/index.ts | 3 + src/hooks/useViaCep/types.ts | 12 + src/hooks/useViaCep/useViaCep.ts | 10 + src/lib/utils.ts | 40 +- src/pages/AboutUs/AboutUs.tsx | 180 +++++++ .../AboutCardInfo/AboutCardInfo.tsx | 42 ++ .../AboutUs/components/AboutCardInfo/index.ts | 3 + .../AboutUs/components/AboutCardInfo/types.ts | 7 + .../ServicedFrontInfo/ServicedFrontInfo.tsx | 25 + .../components/ServicedFrontInfo/index.ts | 3 + .../components/ServicedFrontInfo/types.ts | 6 + src/pages/AboutUs/components/index.ts | 4 + src/pages/AboutUs/frontItems.ts | 68 +++ src/pages/AboutUs/index.ts | 3 + src/pages/CreateShelter/CreateShelter.tsx | 102 +++- src/pages/CreateShelter/hardcodedCities.tsx | 498 ++++++++++++++++++ src/pages/CreateSupply/CreateSupply.tsx | 8 + .../EditShelterSupply/EditShelterSupply.tsx | 47 +- .../components/SupplyRow/SupplyRow.tsx | 1 + .../components/SupplyRow/types.ts | 1 + .../SupplyRowInfo/SupplyRowInfo.tsx | 4 +- .../components/SupplyRowInfo/types.ts | 1 + src/pages/Home/Home.tsx | 72 +-- .../Home/components/Filter/CitiesFilter.tsx | 48 ++ src/pages/Home/components/Filter/Filter.tsx | 92 +++- src/pages/Home/components/Filter/types.ts | 2 + .../ShelterListItem/ShelterListItem.tsx | 12 +- .../ShelterListView/ShelterListView.tsx | 24 +- .../Home/components/ShelterListView/types.ts | 3 + src/pages/Home/components/index.ts | 6 + src/pages/PrivacyPolicy/PrivacyPolicy.tsx | 184 +++++++ src/pages/PrivacyPolicy/index.ts | 3 + src/pages/Shelter/Shelter.tsx | 14 +- .../ShelterCategoryItems.tsx | 33 +- .../components/ShelterCategoryItems/types.ts | 1 + src/pages/SignIn/types.ts | 10 - src/pages/UpdateShelter/UpdateShelter.tsx | 103 +++- src/pages/UpdateShelter/types.ts | 26 +- src/pages/index.ts | 6 +- src/routes/Routes.tsx | 4 + src/service/sessions/session.service.ts | 2 +- src/service/shelter/types.ts | 7 +- src/service/shelterSupply/types.ts | 5 +- 86 files changed, 2205 insertions(+), 216 deletions(-) create mode 100644 .github/ISSUE_TEMPLATE/bug-report.md create mode 100644 src/components/BurgerMenu/BurgerMenu.tsx create mode 100644 src/components/BurgerMenu/components/BurguerMenuItem/BurguerMenuItem.tsx create mode 100644 src/components/BurgerMenu/components/BurguerMenuItem/index.ts create mode 100644 src/components/BurgerMenu/components/BurguerMenuItem/types.ts create mode 100644 src/components/BurgerMenu/components/index.ts create mode 100644 src/components/BurgerMenu/index.ts create mode 100644 src/components/CardAboutShelter/utils.ts create mode 100644 src/components/ui/sheet.tsx create mode 100644 src/hooks/useAuthRoles/index.ts create mode 100644 src/hooks/useAuthRoles/useAuthRoles.tsx create mode 100644 src/hooks/useDebouncedValue/index.ts create mode 100644 src/hooks/useDebouncedValue/useDebouncedValue.ts create mode 100644 src/hooks/useGithubContributors/index.ts create mode 100644 src/hooks/useGithubContributors/types.ts create mode 100644 src/hooks/useGithubContributors/useGithubContributors.tsx create mode 100644 src/hooks/usePartners/index.ts create mode 100644 src/hooks/usePartners/types.ts create mode 100644 src/hooks/usePartners/usePartners.tsx create mode 100644 src/hooks/useShelterCities/index.ts create mode 100644 src/hooks/useShelterCities/types.ts create mode 100644 src/hooks/useShelterCities/useShelterCities.ts create mode 100644 src/hooks/useViaCep/index.ts create mode 100644 src/hooks/useViaCep/types.ts create mode 100644 src/hooks/useViaCep/useViaCep.ts create mode 100644 src/pages/AboutUs/AboutUs.tsx create mode 100644 src/pages/AboutUs/components/AboutCardInfo/AboutCardInfo.tsx create mode 100644 src/pages/AboutUs/components/AboutCardInfo/index.ts create mode 100644 src/pages/AboutUs/components/AboutCardInfo/types.ts create mode 100644 src/pages/AboutUs/components/ServicedFrontInfo/ServicedFrontInfo.tsx create mode 100644 src/pages/AboutUs/components/ServicedFrontInfo/index.ts create mode 100644 src/pages/AboutUs/components/ServicedFrontInfo/types.ts create mode 100644 src/pages/AboutUs/components/index.ts create mode 100644 src/pages/AboutUs/frontItems.ts create mode 100644 src/pages/AboutUs/index.ts create mode 100644 src/pages/CreateShelter/hardcodedCities.tsx create mode 100644 src/pages/Home/components/Filter/CitiesFilter.tsx create mode 100644 src/pages/Home/components/index.ts create mode 100644 src/pages/PrivacyPolicy/PrivacyPolicy.tsx create mode 100644 src/pages/PrivacyPolicy/index.ts delete mode 100644 src/pages/SignIn/types.ts diff --git a/.github/ISSUE_TEMPLATE/bug-report.md b/.github/ISSUE_TEMPLATE/bug-report.md new file mode 100644 index 00000000..d325e134 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug-report.md @@ -0,0 +1,29 @@ +--- +name: Bug report +about: Um modelo exemplo para você relatar algum defeito que tenha encontrado no site. +title: "[BUG] Título do problema" +labels: bug +assignees: '' + +--- +# Descrição +Aqui você escreve sobre o que é o defeito. + +# Problema encontrado +Aqui você dá detalhes sobre o problema, incluíndo os passos para reproduzir, se necessário. + +# Prioridade +Registre apenas a prioridade ou seriedade do defeito. Um guia: +- Crítico: site fora do ar, erros fatas que impedem utilização por completo, página em branco +- Grave: site online, mas com defeito sério que impedem o uso de forma considerável +- Média: defeito não tão sério, mas que dificulta o uso da aplicação de modo geral +- Baixa: coisas poucas, sistema pode ser usado. Problemas de grafia são incluídos aqui + +# Solução proposta +Como deveria ser o comportamento sem o defeito? + +# Ambiente +Aqui você escreve o tipo de dispositivo (Modelo do celular ou sistema operacional do computador) e o navegador que utilizou para o teste. + +# Evidência +Adicione o que for possível, como captura de tela ou vídeo evidenciando o problema. \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 479b79fc..33731021 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,8 +34,7 @@ "react-select": "^5.8.0", "tailwind-merge": "^2.3.0", "tailwindcss-animate": "^1.0.7", - "yup": "^1.4.0", - "zod": "^3.23.6" + "yup": "^1.4.0" }, "devDependencies": { "@types/node": "^20.12.8", @@ -6000,14 +5999,6 @@ "toposort": "^2.0.2", "type-fest": "^2.19.0" } - }, - "node_modules/zod": { - "version": "3.23.6", - "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.6.tgz", - "integrity": "sha512-RTHJlZhsRbuA8Hmp/iNL7jnfc4nZishjsanDAfEY1QpDQZCahUp3xDzl+zfweE9BklxMUcgBgS1b7Lvie/ZVwA==", - "funding": { - "url": "https://github.com/sponsors/colinhacks" - } } } } diff --git a/package.json b/package.json index 325b0666..29dd3ef1 100644 --- a/package.json +++ b/package.json @@ -28,30 +28,29 @@ "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", - "zod": "^3.23.6" + "yup": "^1.4.0" }, "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/Authenticated/Authenticated.tsx b/src/components/Authenticated/Authenticated.tsx index 4c4011f1..9b51d6d0 100644 --- a/src/components/Authenticated/Authenticated.tsx +++ b/src/components/Authenticated/Authenticated.tsx @@ -1,21 +1,12 @@ -import { Fragment, useContext } from 'react'; +import { Fragment } from 'react'; -import { SessionContext } from '@/contexts'; import { IAuthenticatedProps } from './types'; -import { AccessLevel } from '@/service/sessions/types'; - -const MappedRoles: Record = { - Admin: ['Admin'], - DistributionCenter: ['Admin', 'DistributionCenter'], - Staff: ['Admin', 'Staff'], - User: ['Admin', 'Staff', 'DistributionCenter', 'User'], -}; +import { useAuthRoles } from '@/hooks'; const Authenticated = ({ children, role = 'User' }: IAuthenticatedProps) => { - const { session } = useContext(SessionContext); + const isAuthenticated = useAuthRoles(role); - if (!session || !MappedRoles[role].includes(session.accessLevel)) - return ; + if (!isAuthenticated) return ; return
{children}
; }; diff --git a/src/components/BurgerMenu/BurgerMenu.tsx b/src/components/BurgerMenu/BurgerMenu.tsx new file mode 100644 index 00000000..d42249a7 --- /dev/null +++ b/src/components/BurgerMenu/BurgerMenu.tsx @@ -0,0 +1,98 @@ +import { Fragment, useCallback, useContext } from 'react'; +import { + CircleHelp, + CirclePlus, + DoorOpen, + Info, + LinkIcon, + Menu, +} from 'lucide-react'; + +import { SessionServices } from '@/service'; +import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet'; +import { BurguerMenuItem } from './components'; +import { Separator } from '../ui/separator'; +import { SessionContext } from '@/contexts'; +import { usePartners } from '@/hooks'; + +const BurgerMenu = () => { + const { session } = useContext(SessionContext); + const { data: partners } = usePartners(); + + const logout = useCallback(() => { + SessionServices.logout() + .then(() => { + localStorage.removeItem('token'); + window.location.href = '/'; + }) + .catch((err) => { + console.log(`Erro ao realizar logout: ${err}`); + }); + }, []); + + return ( + + + + + +
+ {session && ( + +
+ Olá, {session.name} +
+ +
+ )} + } + /> + } + /> + } + /> + } + /> + + {partners.length > 0 && ( + + Parcerias + {partners.map((partner, idx) => ( + } + /> + ))} + + )} +
+ {session && ( +
+ + Sair + +
+ )} +
+ + ); +}; + +export { BurgerMenu }; diff --git a/src/components/BurgerMenu/components/BurguerMenuItem/BurguerMenuItem.tsx b/src/components/BurgerMenu/components/BurguerMenuItem/BurguerMenuItem.tsx new file mode 100644 index 00000000..98d8a4c4 --- /dev/null +++ b/src/components/BurgerMenu/components/BurguerMenuItem/BurguerMenuItem.tsx @@ -0,0 +1,30 @@ +import React from 'react'; + +import { IBurguerMenuItemProps } from './types'; +import { cn } from '@/lib/utils'; + +const BurguerMenuItem = React.forwardRef< + HTMLAnchorElement, + IBurguerMenuItemProps +>((props, ref) => { + const { icon, label, onClick, link, className = '', ...rest } = props; + + return ( + + {icon} + {label} + + ); +}); + +export { BurguerMenuItem }; diff --git a/src/components/BurgerMenu/components/BurguerMenuItem/index.ts b/src/components/BurgerMenu/components/BurguerMenuItem/index.ts new file mode 100644 index 00000000..2a667c14 --- /dev/null +++ b/src/components/BurgerMenu/components/BurguerMenuItem/index.ts @@ -0,0 +1,3 @@ +import { BurguerMenuItem } from './BurguerMenuItem'; + +export { BurguerMenuItem }; diff --git a/src/components/BurgerMenu/components/BurguerMenuItem/types.ts b/src/components/BurgerMenu/components/BurguerMenuItem/types.ts new file mode 100644 index 00000000..d48e5ec0 --- /dev/null +++ b/src/components/BurgerMenu/components/BurguerMenuItem/types.ts @@ -0,0 +1,7 @@ +export interface IBurguerMenuItemProps + extends React.ComponentPropsWithoutRef<'a'> { + label: string; + icon?: React.ReactNode; + link?: string; + onClick?: () => void; +} diff --git a/src/components/BurgerMenu/components/index.ts b/src/components/BurgerMenu/components/index.ts new file mode 100644 index 00000000..2a667c14 --- /dev/null +++ b/src/components/BurgerMenu/components/index.ts @@ -0,0 +1,3 @@ +import { BurguerMenuItem } from './BurguerMenuItem'; + +export { BurguerMenuItem }; diff --git a/src/components/BurgerMenu/index.ts b/src/components/BurgerMenu/index.ts new file mode 100644 index 00000000..4355a097 --- /dev/null +++ b/src/components/BurgerMenu/index.ts @@ -0,0 +1,3 @@ +import { BurgerMenu } from "./BurgerMenu"; + +export { BurgerMenu }; diff --git a/src/components/CardAboutShelter/CardAboutShelter.tsx b/src/components/CardAboutShelter/CardAboutShelter.tsx index 704314cf..cff1ea22 100644 --- a/src/components/CardAboutShelter/CardAboutShelter.tsx +++ b/src/components/CardAboutShelter/CardAboutShelter.tsx @@ -5,11 +5,14 @@ import { PawPrint, Landmark, Smartphone, + Building, + MapPinned, } from 'lucide-react'; import { Card } from '../ui/card'; import { ICardAboutShelter } from './types'; import { InfoRow } from './components'; +import { checkAndFormatAddress } from './utils'; const CardAboutShelter = (props: ICardAboutShelter) => { const { shelter } = props; @@ -17,12 +20,19 @@ const CardAboutShelter = (props: ICardAboutShelter) => { const check = (v?: string | number | boolean | null) => { return v !== undefined && v !== null; }; + const formatAddress = checkAndFormatAddress(shelter, false); return (
Sobre o abrigo
- } label={shelter.address} /> + } label={formatAddress} /> + {Boolean(shelter.city) && ( + } label="Cidade:" value={shelter.city} /> + )} + {Boolean(shelter.zipCode) && ( + } label="CEP:" value={shelter.zipCode} /> + )} } label={ diff --git a/src/components/CardAboutShelter/components/InfoRow/InfoRow.tsx b/src/components/CardAboutShelter/components/InfoRow/InfoRow.tsx index 0b5f0f61..da5007a2 100644 --- a/src/components/CardAboutShelter/components/InfoRow/InfoRow.tsx +++ b/src/components/CardAboutShelter/components/InfoRow/InfoRow.tsx @@ -4,12 +4,21 @@ import { IInfoRowProps } from './types'; const InfoRow = React.forwardRef( (props, ref) => { - const { icon, label, value, clipboardButton = false, className = '', ...rest } = props; + const { + icon, + label, + value, + clipboardButton = false, + className = '', + ...rest + } = props; const isLink = value?.startsWith('http'); const ValueComp = !value ? ( ) : isLink ? ( - {value} @@ -46,7 +55,6 @@ const InfoRow = React.forwardRef(
)} - ); diff --git a/src/components/CardAboutShelter/index.ts b/src/components/CardAboutShelter/index.ts index 9cc91886..e171498b 100644 --- a/src/components/CardAboutShelter/index.ts +++ b/src/components/CardAboutShelter/index.ts @@ -1,3 +1,4 @@ -import { CardAboutShelter } from "./CardAboutShelter"; +import { CardAboutShelter } from './CardAboutShelter'; +import { checkAndFormatAddress } from './utils'; -export { CardAboutShelter }; +export { CardAboutShelter, checkAndFormatAddress }; diff --git a/src/components/CardAboutShelter/utils.ts b/src/components/CardAboutShelter/utils.ts new file mode 100644 index 00000000..58d00b67 --- /dev/null +++ b/src/components/CardAboutShelter/utils.ts @@ -0,0 +1,28 @@ +import { IUseShelterData } from '@/hooks/useShelter/types'; + +const formatShelterAddressFields = ( + payload: Partial< + Pick + > +): string => { + const { street, streetNumber, neighbourhood } = payload; + return [street, streetNumber, neighbourhood].filter(Boolean).join(', '); +}; + +const checkAndFormatAddress = ( + payload: Partial< + Pick< + IUseShelterData, + 'address' | 'city' | 'street' | 'streetNumber' | 'neighbourhood' + > + >, + showCity = true +): string => { + const { address, city, ...rest } = payload; + return ( + address ?? + `${formatShelterAddressFields(rest)}${showCity ? ` - ${city}` : ''}` + ); +}; + +export { checkAndFormatAddress }; diff --git a/src/components/Chip/Chip.tsx b/src/components/Chip/Chip.tsx index c92a091b..6440a5c3 100644 --- a/src/components/Chip/Chip.tsx +++ b/src/components/Chip/Chip.tsx @@ -5,7 +5,7 @@ import { cva } from 'class-variance-authority'; const Chip = React.forwardRef((props, ref) => { const { label, className, variant = 'info', ...rest } = props; - const variants = cva('px-4 py-1 font-normal text-sm md:text-md rounded-3xl', { + const variants = cva('px-4 py-1.5 font-medium text-sm md:text-md rounded-2xl', { variants: { variant: { warn: 'bg-light-yellow', @@ -21,9 +21,9 @@ const Chip = React.forwardRef((props, ref) => { }); return ( -
+ {label} -
+ ); }); diff --git a/src/components/Chip/types.ts b/src/components/Chip/types.ts index 82c2e70d..22bfb972 100644 --- a/src/components/Chip/types.ts +++ b/src/components/Chip/types.ts @@ -3,4 +3,5 @@ export type ChipVariant = 'info' | 'success' | 'warn' | 'danger'; export interface IChipProps extends React.ComponentPropsWithoutRef<'div'> { label: string; variant?: ChipVariant; + quantity?: number; } diff --git a/src/components/DialogSelector/DialogSelector.tsx b/src/components/DialogSelector/DialogSelector.tsx index 4209bff9..5f23c2e8 100644 --- a/src/components/DialogSelector/DialogSelector.tsx +++ b/src/components/DialogSelector/DialogSelector.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useState, useRef } from 'react'; import { Dialog, @@ -12,6 +12,7 @@ import { IDialogSelectorProps } from './types'; import { RadioGroup, RadioGroupItem } from '../ui/radio-group'; import { Label } from '../ui/label'; import { Button } from '../ui/button'; +import { Input } from '../ui/input'; const DialogSelector = (props: IDialogSelectorProps) => { const { @@ -21,10 +22,23 @@ const DialogSelector = (props: IDialogSelectorProps) => { description, options, value, + quantity: quantityProp, onSave, isSubmitting, } = props; const [selectedItem, setSelectedItem] = useState(value); + const selectedItemRef = useRef(value); // to prevent dated prop values bug on the previous line + const [quantity, setQuantity] = useState(quantityProp); + const quantityRef = useRef(quantityProp); + + if (quantityRef.current !== quantityProp) { + setQuantity(quantityProp); + quantityRef.current = quantityProp; + } + if (selectedItemRef.current !== value) { + setSelectedItem(value); + selectedItemRef.current = value; + } return ( @@ -33,15 +47,36 @@ const DialogSelector = (props: IDialogSelectorProps) => { {title} {description && {description}} -
+
+ +
+ setQuantity(+event.target.value)} + placeholder="Quantidade" + min={0} + /> +
+
+
setSelectedItem(v)} > {options.map((option, idx) => (
- - + +
))}
@@ -50,7 +85,9 @@ const DialogSelector = (props: IDialogSelectorProps) => {