Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 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 @@ -12,6 +12,7 @@
"dependencies": {
"@hookform/resolvers": "^3.3.4",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-label": "^2.0.2",
Expand Down
36 changes: 36 additions & 0 deletions src/components/ConfirmDialog/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import { IConfirmDialog } from "./type";

export function ConfirmDialog(props: IConfirmDialog) {
const red: string = "rgb(220 38 38)"
return (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button variant={props.variant}>{props.label}</Button>
</AlertDialogTrigger>
<AlertDialogContent style={{ zIndex: 1000 }}>
<AlertDialogHeader>
<AlertDialogTitle>{props.title}</AlertDialogTitle>
<AlertDialogDescription>
{props.description}
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter style={{ display: "flex", flexDirection: "row" }}>
<AlertDialogAction style={{ color: red, backgroundColor: "transparent", width: "100%" }} onClick={props.onClickConfirm}>{props.labelOnConfirm}</AlertDialogAction>
<AlertDialogCancel style={{ color: "white", backgroundColor: red, width: "100%" }}>{props.labelOnCancel}</AlertDialogCancel>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
)
}
3 changes: 3 additions & 0 deletions src/components/ConfirmDialog/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { ConfirmDialog } from "./ConfirmDialog";

export { ConfirmDialog };
9 changes: 9 additions & 0 deletions src/components/ConfirmDialog/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface IConfirmDialog {
variant: any
label: string
title: string
description: string
labelOnConfirm: string
labelOnCancel: string
onClickConfirm: (() => void) | undefined
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { IDonateItem } from '@/service/donationOrder/types';
import { TextField } from '../../../TextField';
import { ICreateUser } from '@/service/users/types';
import { IDonationCartForm } from './types';
import { ConfirmDialog } from '@/components/ConfirmDialog/ConfirmDialog';
import { toast } from '@/components/ui/use-toast';

const DonationCartForm = React.forwardRef<HTMLFormElement, IDonationCartForm>(
(props, ref) => {
Expand All @@ -39,6 +41,9 @@ const DonationCartForm = React.forwardRef<HTMLFormElement, IDonationCartForm>(
const handleCancelCart = useCallback(() => {
clearCart(shelterId);
if (onCancel) onCancel();
toast({
title: 'Doação cancelada com sucesso',
});
}, [clearCart, onCancel, shelterId]);

const handleChangeQuantity = useCallback(
Expand Down Expand Up @@ -251,9 +256,15 @@ const DonationCartForm = React.forwardRef<HTMLFormElement, IDonationCartForm>(
</div>
<SheetFooter className="border-t-[1px] border-border">
<div className="w-full flex justify-between p-4">
<Button size="sm" variant="ghost" onClick={handleCancelCart}>
Cancelar
</Button>
<ConfirmDialog
variant="ghost"
label="Cancelar"
title="Você realmente deseja cancelar esta doação?"
description="Essa ação não pode ser desfeita"
labelOnConfirm="Sim"
labelOnCancel="Não"
onClickConfirm={handleCancelCart}>
</ConfirmDialog>
<Button
type="submit"
disabled={cart.length === 0}
Expand Down
139 changes: 139 additions & 0 deletions src/components/ui/alert-dialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import * as React from "react"
import * as AlertDialogPrimitive from "@radix-ui/react-alert-dialog"

import { cn } from "@/lib/utils"
import { buttonVariants } from './button-variants'

const AlertDialog = AlertDialogPrimitive.Root

const AlertDialogTrigger = AlertDialogPrimitive.Trigger

const AlertDialogPortal = AlertDialogPrimitive.Portal

const AlertDialogOverlay = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Overlay
className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}
ref={ref}
/>
))
AlertDialogOverlay.displayName = AlertDialogPrimitive.Overlay.displayName

const AlertDialogContent = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Content>
>(({ className, ...props }, ref) => (
<AlertDialogPortal>
<AlertDialogOverlay />
<AlertDialogPrimitive.Content
ref={ref}
className={cn(
"fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className
)}
{...props}
/>
</AlertDialogPortal>
))
AlertDialogContent.displayName = AlertDialogPrimitive.Content.displayName

const AlertDialogHeader = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col space-y-2 text-center sm:text-left",
className
)}
{...props}
/>
)
AlertDialogHeader.displayName = "AlertDialogHeader"

const AlertDialogFooter = ({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) => (
<div
className={cn(
"flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",
className
)}
{...props}
/>
)
AlertDialogFooter.displayName = "AlertDialogFooter"

const AlertDialogTitle = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Title>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Title
ref={ref}
className={cn("text-lg font-semibold", className)}
{...props}
/>
))
AlertDialogTitle.displayName = AlertDialogPrimitive.Title.displayName

const AlertDialogDescription = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Description>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Description
ref={ref}
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
))
AlertDialogDescription.displayName =
AlertDialogPrimitive.Description.displayName

const AlertDialogAction = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Action>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Action>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Action
ref={ref}
className={cn(buttonVariants(), className)}
{...props}
/>
))
AlertDialogAction.displayName = AlertDialogPrimitive.Action.displayName

const AlertDialogCancel = React.forwardRef<
React.ElementRef<typeof AlertDialogPrimitive.Cancel>,
React.ComponentPropsWithoutRef<typeof AlertDialogPrimitive.Cancel>
>(({ className, ...props }, ref) => (
<AlertDialogPrimitive.Cancel
ref={ref}
className={cn(
buttonVariants({ variant: "outline" }),
"mt-2 sm:mt-0",
className
)}
{...props}
/>
))
AlertDialogCancel.displayName = AlertDialogPrimitive.Cancel.displayName

export {
AlertDialog,
AlertDialogPortal,
AlertDialogOverlay,
AlertDialogTrigger,
AlertDialogContent,
AlertDialogHeader,
AlertDialogFooter,
AlertDialogTitle,
AlertDialogDescription,
AlertDialogAction,
AlertDialogCancel,
}