♻️ 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 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 {
webhookUrl: string;
@ -15,7 +15,6 @@ const WebhookCard = ({ webhookUrl, onDelete }: WebhookCardProps) => {
return (
<div className="flex justify-between w-full mb-3">
{webhookUrl}
<div className="flex gap-3">
<Button
size="sm"
@ -38,23 +37,15 @@ const WebhookCard = ({ webhookUrl, onDelete }: WebhookCardProps) => {
X
</Button>
</div>
<ConfirmDialog
dialogTitle="Delete webhook"
handleOpen={() => setDeleteDialogOpen((preVal) => !preVal)}
<DeleteWebhookDialog
handleCancel={() => setDeleteDialogOpen((preVal) => !preVal)}
open={deleteDialogOpen}
confirmButtonTitle="Yes, Confirm delete"
handleConfirm={() => {
setDeleteDialogOpen((preVal) => !preVal);
onDelete();
}}
color="red"
>
<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>
webhookUrl={webhookUrl}
/>
</div>
);
};