import { GridPagination } from '@components/admin/grid/GridPagination.js'; import { DummyColumnHeader } from '@components/admin/grid/header/Dummy.js'; import { SortableHeader } from '@components/admin/grid/header/Sortable.js'; import { Status } from '@components/admin/Status.js'; import Area from '@components/common/Area.js'; import { Form } from '@components/common/form/Form.js'; import { InputField } from '@components/common/form/InputField.js'; import { useAlertContext } from '@components/common/modal/Alert.js'; import { Button } from '@components/common/ui/Button.js'; import { ButtonGroup } from '@components/common/ui/ButtonGroup.js'; import { Card } from '@components/common/ui/Card.js'; import { CardAction, CardContent, CardHeader } from '@components/common/ui/Card.js'; import { Checkbox } from '@components/common/ui/Checkbox.js'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@components/common/ui/Table.js'; import { _ } from '@evershop/evershop/lib/locale/translate/_'; import axios from 'axios'; import { Copy, LayoutTemplate } from 'lucide-react'; import React, { useState } from 'react'; import { LandingPageName } from './rows/LandingPageName.js'; interface LandingPageItem { landingPageId: number; uuid: string; name: string; urlKey: string; status: boolean; url: string; editUrl: string; updateApi: string; deleteApi: string; duplicateApi: string; pageBuilderUrl: string; } interface Filter { key: string; operation: string; value: string; } function Actions({ landingPages = [], selectedIds = [] }: { landingPages: LandingPageItem[]; selectedIds: string[]; }) { const { openAlert, closeAlert } = useAlertContext(); const [, setIsLoading] = useState(false); const updateLandingPages = async (status: boolean) => { setIsLoading(true); const promises = landingPages .filter((landingPage) => selectedIds.includes(landingPage.uuid)) .map((landingPage) => axios.patch(landingPage.updateApi, { status })); await Promise.all(promises); setIsLoading(false); // Refresh the page window.location.reload(); }; const deleteLandingPages = async () => { setIsLoading(true); const promises = landingPages .filter((landingPage) => selectedIds.includes(landingPage.uuid)) .map((landingPage) => axios.delete(landingPage.deleteApi)); await Promise.all(promises); setIsLoading(false); // Refresh the page window.location.reload(); }; const actions = [ { name: _('Disable'), onAction: () => { openAlert({ heading: _('Disable ${count} landing pages', { count: String(selectedIds.length) }), content: _('Are you sure?'), primaryAction: { title: _('Cancel'), onAction: closeAlert, variant: 'secondary' }, secondaryAction: { title: _('Disable'), onAction: async () => { await updateLandingPages(false); }, variant: 'destructive' } }); } }, { name: _('Enable'), onAction: () => { openAlert({ heading: _('Enable ${count} landing pages', { count: String(selectedIds.length) }), content: _('Are you sure?'), primaryAction: { title: _('Cancel'), onAction: closeAlert, variant: 'secondary' }, secondaryAction: { title: _('Enable'), onAction: async () => { await updateLandingPages(true); }, variant: 'destructive' } }); } }, { name: _('Delete'), onAction: () => { openAlert({ heading: _('Delete ${count} landing pages', { count: String(selectedIds.length) }), content: