Skip to content

Commit

Permalink
refactor: donation history page (#346)
Browse files Browse the repository at this point in the history
Refatoração da tela de doações
  • Loading branch information
rhuam authored Jun 5, 2024
2 parents 551cfa2 + a84b04f commit eba3fd2
Show file tree
Hide file tree
Showing 31 changed files with 488 additions and 473 deletions.
32 changes: 32 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@radix-ui/react-select": "^2.0.0",
"@radix-ui/react-separator": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toast": "^1.1.5",
"@radix-ui/react-tooltip": "^1.0.7",
"axios": "^1.6.8",
Expand Down
10 changes: 8 additions & 2 deletions src/components/BurgerMenu/BurgerMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import {
ShieldAlert,
X,
} from 'lucide-react';
import clsx from 'clsx';

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';
import { DialogClose } from '@radix-ui/react-dialog';
import { Button } from '../ui/button';
import { DialogFooter } from '../ui/dialog';
import { DialogClose, DialogFooter } from '../ui/dialog';

const BurgerMenu = () => {
const { session } = useContext(SessionContext);
Expand Down Expand Up @@ -63,6 +63,12 @@ const BurgerMenu = () => {
link="/sobre-nos"
icon={<Info className="w-5 h-5" />}
/>
<BurguerMenuItem
label="Minhas Doações"
link="/doacoes"
icon={<HeartHandshake className="w-5 h-5" />}
className={clsx({ hidden: !session })}
/>
<BurguerMenuItem
label="Cadastrar abrigo"
link="https://forms.gle/2S7L2gR529Dc8P3T9"
Expand Down
5 changes: 4 additions & 1 deletion src/components/DonationCart/DonationCart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const DonationCart = (props: IDonationCart) => {

return (
<Sheet open={opened} onOpenChange={onClose}>
<SheetContent side="right" className="z-[120] flex flex-col pb-0 px-0">
<SheetContent
side="right"
className="z-[120] flex flex-col pb-0 px-0 overflow-y-auto"
>
{donationOrderId ? (
<DonationSuccess donationOrderId={donationOrderId} />
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ const DonationSuccess = React.forwardRef<HTMLDivElement, IDonationSuccessProps>(
if (loading)
return <Loader className="stroke-gray-500 w-6 h-6 animate-spin" />;

const handleRedirect = () => {
navigate(`/abrigo/${donation.shelter.id}/doacoes`);
};

return (
<div ref={ref} className={cn('contents', className)} {...rest}>
<SheetHeader className="px-4">
Expand Down Expand Up @@ -80,7 +76,7 @@ const DonationSuccess = React.forwardRef<HTMLDivElement, IDonationSuccessProps>(
<Button
className="w-full"
variant="destructive"
onClick={handleRedirect}
onClick={() => navigate('/doacoes')}
>
Verificar histórico de doações
</Button>
Expand Down
12 changes: 12 additions & 0 deletions src/components/Loader/Loader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Loader2 } from 'lucide-react';
import { ILoader } from './types';

const Loader = (props: ILoader) => {
const { loading, children } = props;

if (loading) return <Loader2 className="w-5 h-5 animate-spin" />;

return children;
};

export { Loader };
3 changes: 3 additions & 0 deletions src/components/Loader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Loader } from './Loader';

export { Loader };
4 changes: 4 additions & 0 deletions src/components/Loader/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface ILoader {
loading: boolean;
children?: React.ReactNode;
}
2 changes: 2 additions & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { BurgerMenu } from './BurgerMenu';
import { BackToTop } from './BackToTop';
import { DonationCartIcon } from './DonationCartIcon';
import { DonationCart } from './DonationCart';
import { Loader } from './Loader';

export {
LoadingScreen,
Expand All @@ -38,4 +39,5 @@ export {
BackToTop,
DonationCartIcon,
DonationCart,
Loader,
};
53 changes: 53 additions & 0 deletions src/components/ui/tabs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import * as React from "react"
import * as TabsPrimitive from "@radix-ui/react-tabs"

import { cn } from "@/lib/utils"

const Tabs = TabsPrimitive.Root

const TabsList = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.List>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
>(({ className, ...props }, ref) => (
<TabsPrimitive.List
ref={ref}
className={cn(
"inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",
className
)}
{...props}
/>
))
TabsList.displayName = TabsPrimitive.List.displayName

const TabsTrigger = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
>(({ className, ...props }, ref) => (
<TabsPrimitive.Trigger
ref={ref}
className={cn(
"inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",
className
)}
{...props}
/>
))
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName

const TabsContent = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
>(({ className, ...props }, ref) => (
<TabsPrimitive.Content
ref={ref}
className={cn(
"mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
className
)}
{...props}
/>
))
TabsContent.displayName = TabsPrimitive.Content.displayName

export { Tabs, TabsList, TabsTrigger, TabsContent }
2 changes: 2 additions & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useGithubContributors } from './useGithubContributors';
import { useAuthRoles } from './useAuthRoles';
import { useSupporters } from './useSupporters';
import { useDonationOrder } from './useDonationOrder';
import { useDonations } from './useDonations';

export {
useShelters,
Expand All @@ -30,4 +31,5 @@ export {
useAuthRoles,
useSupporters,
useDonationOrder,
useDonations,
};
9 changes: 6 additions & 3 deletions src/hooks/useDonations/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { DonateOrderStatus } from '@/service/donationOrder/types';
import { SupplyMeasure } from '../useShelter/types';

export interface IUseDonationsData {
page: number;
perPage: number;
Expand All @@ -8,18 +11,18 @@ export interface IUseDonationsData {
export interface IDonationsData {
id: string;
userId: string;
status: string;
status: DonateOrderStatus;
shelter: {
id: string;
name: string;
};
donationOrderSupplies: {
quantity: number;
supply: {
measure: string;
measure: SupplyMeasure;
name: string;
};
};
}[];
createdAt: string;
updatedAt: string;
}
11 changes: 9 additions & 2 deletions src/hooks/useDonations/useDonations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ import { useFetch } from '../useFetch';
import { PaginatedQueryPath } from '../usePaginatedQuery/paths';
import { IUseDonationsData } from './types';

const useDonations = (shelterId: string) => {
return useFetch<IUseDonationsData>(`${PaginatedQueryPath.DonationOrder}`);
const useDonations = () => {
return useFetch<IUseDonationsData>(`${PaginatedQueryPath.DonationOrder}`, {
initialValue: {
count: 0,
page: 1,
perPage: 20,
results: [],
},
});
};

export { useDonations };
17 changes: 17 additions & 0 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ShelterCategory, SupplyMeasure } from '@/hooks/useShelter/types';
import { IUseSheltersDataSupplyData } from '@/hooks/useShelters/types';
import { ShelterAvailabilityStatus } from '@/pages/Home/components/Filter/types';
import {
ShelterTagInfo,
ShelterTagType,
} from '@/pages/Home/components/ShelterListItem/types';
import { DonateOrderStatus } from '@/service/donationOrder/types';
import { SupplyPriority } from '@/service/supply/types';
import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
Expand Down Expand Up @@ -158,6 +160,19 @@ const SupplyMeasureMap: Record<SupplyMeasure, string> = {
Unit: 'un',
};

const ShelterAvailabilityStatusMap: Record<ShelterAvailabilityStatus, string> =
{
available: 'Abrigo Disponivel',
unavailable: 'Abrigo Indisponivel',
waiting: 'Sem informação de disponibilidade',
};

const DonationStatusMap: Record<DonateOrderStatus, string> = {
[DonateOrderStatus.Canceled]: 'Cancelado',
[DonateOrderStatus.Pending]: 'Pendente',
[DonateOrderStatus.Complete]: 'Entregue',
};

export {
cn,
getAvailabilityProps,
Expand All @@ -169,4 +184,6 @@ export {
normalizedCompare,
checkIsNull,
SupplyMeasureMap,
ShelterAvailabilityStatusMap,
DonationStatusMap,
};
Loading

0 comments on commit eba3fd2

Please sign in to comment.