|
@@ -1,14 +1,15 @@
|
|
|
import { DataTable } from '@/vdb/components/data-table/data-table.js';
|
|
import { DataTable } from '@/vdb/components/data-table/data-table.js';
|
|
|
|
|
+import { useGeneratedColumns } from '@/vdb/components/data-table/use-generated-columns.js';
|
|
|
import { CountrySelector } from '@/vdb/components/shared/country-selector.js';
|
|
import { CountrySelector } from '@/vdb/components/shared/country-selector.js';
|
|
|
import { api } from '@/vdb/graphql/api.js';
|
|
import { api } from '@/vdb/graphql/api.js';
|
|
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
import { useMutation, useQuery } from '@tanstack/react-query';
|
|
|
-import { ColumnDef } from '@tanstack/react-table';
|
|
|
|
|
|
|
+import { Trans } from '@lingui/react/macro';
|
|
|
import { useMemo, useState } from 'react';
|
|
import { useMemo, useState } from 'react';
|
|
|
import {
|
|
import {
|
|
|
addCountryToZoneMutation,
|
|
addCountryToZoneMutation,
|
|
|
- removeCountryFromZoneMutation,
|
|
|
|
|
zoneMembersQuery,
|
|
zoneMembersQuery,
|
|
|
} from '../zones.graphql.js';
|
|
} from '../zones.graphql.js';
|
|
|
|
|
+import { removeCountryFromZoneBulkAction } from './zone-bulk-actions.js';
|
|
|
|
|
|
|
|
interface ZoneCountriesTableProps {
|
|
interface ZoneCountriesTableProps {
|
|
|
zoneId: string;
|
|
zoneId: string;
|
|
@@ -35,31 +36,48 @@ export function ZoneCountriesTable({ zoneId, canAddCountries = false }: Readonly
|
|
|
return data?.zone?.members?.slice((page - 1) * pageSize, page * pageSize);
|
|
return data?.zone?.members?.slice((page - 1) * pageSize, page * pageSize);
|
|
|
}, [data, page, pageSize]);
|
|
}, [data, page, pageSize]);
|
|
|
|
|
|
|
|
- const columns: ColumnDef<any>[] = [
|
|
|
|
|
- {
|
|
|
|
|
- header: 'Country',
|
|
|
|
|
- accessorKey: 'name',
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- header: 'Enabled',
|
|
|
|
|
- accessorKey: 'enabled',
|
|
|
|
|
- },
|
|
|
|
|
- {
|
|
|
|
|
- header: 'Code',
|
|
|
|
|
- accessorKey: 'code',
|
|
|
|
|
|
|
+ const bulkActions = useMemo(
|
|
|
|
|
+ () => [
|
|
|
|
|
+ {
|
|
|
|
|
+ component: removeCountryFromZoneBulkAction(zoneId),
|
|
|
|
|
+ order: 500,
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ [zoneId],
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ const { columns } = useGeneratedColumns({
|
|
|
|
|
+ fields: [],
|
|
|
|
|
+ additionalColumns: {
|
|
|
|
|
+ name: {
|
|
|
|
|
+ header: () => <Trans>Country</Trans>,
|
|
|
|
|
+ accessorKey: 'name',
|
|
|
|
|
+ },
|
|
|
|
|
+ enabled: {
|
|
|
|
|
+ header: () => <Trans>Enabled</Trans>,
|
|
|
|
|
+ accessorKey: 'enabled',
|
|
|
|
|
+ },
|
|
|
|
|
+ code: {
|
|
|
|
|
+ header: () => <Trans>Code</Trans>,
|
|
|
|
|
+ accessorKey: 'code',
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
- ];
|
|
|
|
|
|
|
+ bulkActions,
|
|
|
|
|
+ includeActionsColumn: false,
|
|
|
|
|
+ enableSorting: false,
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div>
|
|
<div>
|
|
|
<DataTable
|
|
<DataTable
|
|
|
- columns={columns}
|
|
|
|
|
|
|
+ columns={columns as any}
|
|
|
data={paginatedItems ?? []}
|
|
data={paginatedItems ?? []}
|
|
|
onPageChange={(table, page, itemsPerPage) => {
|
|
onPageChange={(table, page, itemsPerPage) => {
|
|
|
setPage(page);
|
|
setPage(page);
|
|
|
setPageSize(itemsPerPage);
|
|
setPageSize(itemsPerPage);
|
|
|
}}
|
|
}}
|
|
|
totalItems={data?.zone?.members?.length ?? 0}
|
|
totalItems={data?.zone?.members?.length ?? 0}
|
|
|
|
|
+ bulkActions={bulkActions}
|
|
|
/>
|
|
/>
|
|
|
{canAddCountries && (
|
|
{canAddCountries && (
|
|
|
<CountrySelector
|
|
<CountrySelector
|