'use client'; import * as React from 'react'; import RouterLink from 'next/link'; import { LoadingButton } from '@mui/lab'; import Avatar from '@mui/material/Avatar'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import LinearProgress from '@mui/material/LinearProgress'; import Link from '@mui/material/Link'; import Stack from '@mui/material/Stack'; import Typography from '@mui/material/Typography'; import { CheckCircle as CheckCircleIcon } from '@phosphor-icons/react/dist/ssr/CheckCircle'; import { Clock as ClockIcon } from '@phosphor-icons/react/dist/ssr/Clock'; import { Images as ImagesIcon } from '@phosphor-icons/react/dist/ssr/Images'; import { Minus as MinusIcon } from '@phosphor-icons/react/dist/ssr/Minus'; import { PencilSimple as PencilSimpleIcon } from '@phosphor-icons/react/dist/ssr/PencilSimple'; import { TrashSimple as TrashSimpleIcon } from '@phosphor-icons/react/dist/ssr/TrashSimple'; import { useTranslation } from 'react-i18next'; import { toast } from 'sonner'; import { paths } from '@/paths'; import { dayjs } from '@/lib/dayjs'; import { DataTable } from '@/components/core/data-table'; import type { ColumnDef } from '@/components/core/data-table'; import ConfirmDeleteModal from './confirm-delete-modal'; import { useLpQuestionsSelection } from './lp-questions-selection-context'; import type { LpQuestion } from './type'; function columns(handleDeleteClick: (testId: string) => void): ColumnDef[] { return [ { formatter: (row): React.JSX.Element => ( {' '}
{row.cat_name} slug: {row.cat_name}
), name: 'Name', width: '200px', }, { formatter: (row): React.JSX.Element => ( {new Intl.NumberFormat('en-US', { style: 'percent', maximumFractionDigits: 2 }).format(row.quota / 100)} ), // NOTE: please refer to translation.json here name: 'word-count', width: '100px', }, { formatter: (row): React.JSX.Element => { // eslint-disable-next-line react-hooks/rules-of-hooks const mapping = { active: { label: 'Active', icon: ( ), }, blocked: { label: 'Blocked', icon: }, pending: { label: 'Pending', icon: ( ), }, NA: { label: 'NA', icon: ( ), }, } as const; const { label, icon } = mapping[row.status] ?? { label: 'Unknown', icon: null }; return ( ); }, name: 'Status', width: '150px', }, { formatter(row) { return dayjs(row.createdAt).format('MMM D, YYYY'); }, name: 'Created at', width: '100px', }, { formatter: (row): React.JSX.Element => ( { handleDeleteClick(row.id); }} > ), name: 'Actions', hideName: true, width: '100px', align: 'right', }, ]; } export interface LessonQuestionsTableProps { rows: LpQuestion[]; reloadRows: () => void; } export function LpQuestionsTable({ rows, reloadRows }: LessonQuestionsTableProps): React.JSX.Element { const { t } = useTranslation(['lp_categories']); const { deselectAll, deselectOne, selectAll, selectOne, selected } = useLpQuestionsSelection(); const [idToDelete, setIdToDelete] = React.useState(''); const [open, setOpen] = React.useState(false); function handleDeleteClick(testId: string): void { setOpen(true); setIdToDelete(testId); } return ( columns={columns(handleDeleteClick)} onDeselectAll={deselectAll} onDeselectOne={(_, row) => { deselectOne(row.id); }} onSelectAll={selectAll} onSelectOne={(_, row) => { selectOne(row.id); }} rows={rows} selectable selected={selected} /> {!rows.length ? ( {/* TODO: update this */} {t('no-lesson-categories-found')} ) : null} ); }