Skip to content

Commit

Permalink
fix: make deleteConfirmModal work
Browse files Browse the repository at this point in the history
  • Loading branch information
boazpoolman committed Dec 5, 2024
1 parent eedefe2 commit d2c32ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,22 @@ import {
import { WarningCircle } from '@strapi/icons';

type Props = {
isOpen: boolean;
onClose: () => void;
onSubmit: () => void;
children: React.ReactNode;
};

const DeleteConfirmModal = (props: Props) => {
const {
isOpen,
onClose,
onSubmit,
children,
} = props;

const { formatMessage } = useIntl();

if (!isOpen) return null;

return (
<Dialog.Root>
<Dialog.Trigger>
<div>test</div>
{children}
</Dialog.Trigger>
<Dialog.Content>
<Dialog.Header>
Expand All @@ -53,9 +49,6 @@ const DeleteConfirmModal = (props: Props) => {
<Dialog.Footer>
<Dialog.Cancel>
<Button
onClick={() => {
onClose();
}}
variant="tertiary"
>
{formatMessage({
Expand All @@ -67,7 +60,6 @@ const DeleteConfirmModal = (props: Props) => {
<Button
variant="secondary"
onClick={() => {
onClose();
onSubmit();
}}
>
Expand Down
27 changes: 12 additions & 15 deletions packages/core/admin/screens/List/components/TableRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ const TableRow: FC<Props> = ({
onDelete,
}) => {
const { toggleNotification } = useNotification();
const { get } = getFetchClient();
const { get, post } = getFetchClient();
const { formatMessage } = useIntl();
const [openDeleteModal, setOpenDeleteModal] = useState(false);
const navigate = useNavigate();

const handleClick = (path: string) => {
Expand All @@ -46,7 +45,7 @@ const TableRow: FC<Props> = ({
};

const handleDelete = (id: number) => {
get(`/webtools/url-alias/delete/${id}`)
post(`/webtools/url-alias/delete/${id}`)
.then(() => {
if (onDelete) onDelete();
toggleNotification({ type: 'success', message: formatMessage({ id: 'webtools.settings.success.url_alias.delete' }) });
Expand Down Expand Up @@ -93,20 +92,18 @@ const TableRow: FC<Props> = ({
>
<Pencil />
</IconButton>
<IconButton
onClick={() => setOpenDeleteModal(true)}
label={formatMessage(
{ id: 'webtools.settings.page.list.table.actions.delete', defaultMessage: 'Delete {target}' },
{ target: `${row.url_path}` },
)}
>
<Trash />
</IconButton>
<DeleteConfirmModal
isOpen={openDeleteModal}
onClose={() => setOpenDeleteModal(false)}
onSubmit={() => handleDelete(row.id)}
/>
>
<IconButton
label={formatMessage(
{ id: 'webtools.settings.page.list.table.actions.delete', defaultMessage: 'Delete {target}' },
{ target: `${row.url_path}` },
)}
>
<Trash />
</IconButton>
</DeleteConfirmModal>
</Flex>
</Td>
</Tr>
Expand Down

0 comments on commit d2c32ca

Please sign in to comment.