♻️ refactor: create delete webhook dialog component

This commit is contained in:
Wahyu Kurniawan 2024-03-14 21:56:00 +07:00
parent c1696fbf48
commit f5807c1126
No known key found for this signature in database
GPG Key ID: 040A1549143A8E33
2 changed files with 42 additions and 15 deletions

View File

@ -0,0 +1,36 @@
import ConfirmDialog, {
ConfirmDialogProps,
} from 'components/shared/ConfirmDialog';
import React from 'react';
interface DeleteWebhookDialogProps extends ConfirmDialogProps {
webhookUrl: string;
}
export const DeleteWebhookDialog = ({
webhookUrl,
open,
handleCancel,
handleConfirm,
...props
}: DeleteWebhookDialogProps) => {
return (
<ConfirmDialog
{...props}
dialogTitle="Delete webhook?"
handleCancel={handleCancel}
open={open}
confirmButtonTitle="Yes, confirm delete"
handleConfirm={handleConfirm}
confirmButtonProps={{ variant: 'danger' }}
>
<p className="text-sm text-elements-mid-em">
Are you sure you want to delete{' '}
<span className="text-sm font-mono text-elements-high-em px-0.5">
{webhookUrl}
</span>
?
</p>
</ConfirmDialog>
);
};

View File

@ -1,9 +1,9 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import toast from 'react-hot-toast'; import toast from 'react-hot-toast';
import { Button, Typography } from '@material-tailwind/react'; import { Button } from '@material-tailwind/react';
import ConfirmDialog from '../../../shared/ConfirmDialog'; import { DeleteWebhookDialog } from 'components/projects/Dialog/DeleteWebhookDialog';
interface WebhookCardProps { interface WebhookCardProps {
webhookUrl: string; webhookUrl: string;
@ -15,7 +15,6 @@ const WebhookCard = ({ webhookUrl, onDelete }: WebhookCardProps) => {
return ( return (
<div className="flex justify-between w-full mb-3"> <div className="flex justify-between w-full mb-3">
{webhookUrl} {webhookUrl}
<div className="flex gap-3"> <div className="flex gap-3">
<Button <Button
size="sm" size="sm"
@ -38,23 +37,15 @@ const WebhookCard = ({ webhookUrl, onDelete }: WebhookCardProps) => {
X X
</Button> </Button>
</div> </div>
<DeleteWebhookDialog
<ConfirmDialog handleCancel={() => setDeleteDialogOpen((preVal) => !preVal)}
dialogTitle="Delete webhook"
handleOpen={() => setDeleteDialogOpen((preVal) => !preVal)}
open={deleteDialogOpen} open={deleteDialogOpen}
confirmButtonTitle="Yes, Confirm delete"
handleConfirm={() => { handleConfirm={() => {
setDeleteDialogOpen((preVal) => !preVal); setDeleteDialogOpen((preVal) => !preVal);
onDelete(); onDelete();
}} }}
color="red" webhookUrl={webhookUrl}
> />
<Typography variant="small" placeholder={''}>
Are you sure you want to delete the variable{' '}
<span className="bg-blue-100 p-0.5 rounded-sm">{webhookUrl}</span>?
</Typography>
</ConfirmDialog>
</div> </div>
); );
}; };