update refactoring,
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { dayjs } from '@/lib/dayjs';
|
||||
|
||||
import { CreateFormProps, LpCategory } from './type';
|
||||
import { CreateFormProps, MfCategory } from './type';
|
||||
|
||||
export const defaultLpCategory: LpCategory = {
|
||||
export const defaultMfCategory: MfCategory = {
|
||||
isEmpty: false,
|
||||
id: 'default-id',
|
||||
cat_name: 'default-category-name',
|
||||
@@ -38,7 +38,7 @@ export const defaultLpCategory: LpCategory = {
|
||||
// imageUrl: '',
|
||||
// };
|
||||
|
||||
export const emptyLpCategory: LpCategory = {
|
||||
...defaultLpCategory,
|
||||
export const emptyLpCategory: MfCategory = {
|
||||
...defaultMfCategory,
|
||||
isEmpty: true,
|
||||
};
|
||||
|
@@ -3,7 +3,7 @@
|
||||
import * as React from 'react';
|
||||
import RouterLink from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { COL_QUIZ_LP_CATEGORIES } from '@/constants';
|
||||
import { COL_QUIZ_MF_CATEGORIES } from '@/constants';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { LoadingButton } from '@mui/lab';
|
||||
import { Avatar, Divider, MenuItem, Select } from '@mui/material';
|
||||
@@ -66,7 +66,7 @@ export const defaultValues = {
|
||||
description: '',
|
||||
} satisfies Values;
|
||||
|
||||
export function LpCategoryCreateForm(): React.JSX.Element {
|
||||
export function MfCategoryCreateForm(): React.JSX.Element {
|
||||
const router = useRouter();
|
||||
const { t } = useTranslation(['lp_categories']);
|
||||
|
||||
@@ -101,11 +101,11 @@ export function LpCategoryCreateForm(): React.JSX.Element {
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await pb.collection(COL_QUIZ_LP_CATEGORIES).create(payload);
|
||||
const result = await pb.collection(COL_QUIZ_MF_CATEGORIES).create(payload);
|
||||
|
||||
logger.debug(result);
|
||||
toast.success(t('create.success'));
|
||||
router.push(paths.dashboard.lp_categories.list);
|
||||
router.push(paths.dashboard.mf_categories.list);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
toast.error(t('create.failed'));
|
||||
|
@@ -23,8 +23,8 @@ import { paths } from '@/paths';
|
||||
import { FilterButton, FilterPopover, useFilterContext } from '@/components/core/filter-button';
|
||||
import { Option } from '@/components/core/option';
|
||||
|
||||
import { useLpCategoriesSelection } from './lp-categories-selection-context';
|
||||
import { LpCategory } from './type';
|
||||
import { useLpCategoriesSelection } from './mf-categories-selection-context';
|
||||
import { MfCategory } from './type';
|
||||
|
||||
export interface Filters {
|
||||
email?: string;
|
||||
@@ -40,10 +40,10 @@ export type SortDir = 'asc' | 'desc';
|
||||
export interface LpCategoriesFiltersProps {
|
||||
filters?: Filters;
|
||||
sortDir?: SortDir;
|
||||
fullData: LpCategory[];
|
||||
fullData: MfCategory[];
|
||||
}
|
||||
|
||||
export function LpCategoriesFilters({
|
||||
export function MfCategoriesFilters({
|
||||
filters = {},
|
||||
sortDir = 'desc',
|
||||
fullData,
|
||||
@@ -60,13 +60,13 @@ export function LpCategoriesFilters({
|
||||
const selection = useLpCategoriesSelection();
|
||||
|
||||
function getVisible(): number {
|
||||
return fullData.reduce((count, item: LpCategory) => {
|
||||
return fullData.reduce((count, item: MfCategory) => {
|
||||
return item.visible === 'visible' ? count + 1 : count;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function getHidden(): number {
|
||||
return fullData.reduce((count, item: LpCategory) => {
|
||||
return fullData.reduce((count, item: MfCategory) => {
|
||||
return item.visible === 'hidden' ? count + 1 : count;
|
||||
}, 0);
|
||||
}
|
||||
@@ -114,7 +114,7 @@ export function LpCategoriesFilters({
|
||||
}
|
||||
|
||||
// NOTE: modify according to COLLECTION
|
||||
router.push(`${paths.dashboard.lp_categories.list}?${searchParams.toString()}`);
|
||||
router.push(`${paths.dashboard.mf_categories.list}?${searchParams.toString()}`);
|
||||
},
|
||||
[router]
|
||||
);
|
@@ -16,7 +16,7 @@ interface LessonCategoriesPaginationProps {
|
||||
rowsPerPage: number;
|
||||
}
|
||||
|
||||
export function LpCategoriesPagination({
|
||||
export function MfCategoriesPagination({
|
||||
count,
|
||||
page,
|
||||
//
|
@@ -6,7 +6,7 @@ import * as React from 'react';
|
||||
import { useSelection } from '@/hooks/use-selection';
|
||||
import type { Selection } from '@/hooks/use-selection';
|
||||
|
||||
import { LpCategory } from './type';
|
||||
import { MfCategory } from './type';
|
||||
|
||||
function noop(): void {
|
||||
return undefined;
|
||||
@@ -26,10 +26,10 @@ export const LpCategoriesSelectionContext = React.createContext<LpCategoriesSele
|
||||
|
||||
interface LpCategoriesSelectionProviderProps {
|
||||
children: React.ReactNode;
|
||||
lessonCategories: LpCategory[];
|
||||
lessonCategories: MfCategory[];
|
||||
}
|
||||
|
||||
export function LpCategoriesSelectionProvider({
|
||||
export function MfCategoriesSelectionProvider({
|
||||
children,
|
||||
lessonCategories = [],
|
||||
}: LpCategoriesSelectionProviderProps): React.JSX.Element {
|
@@ -25,10 +25,10 @@ import { DataTable } from '@/components/core/data-table';
|
||||
import type { ColumnDef } from '@/components/core/data-table';
|
||||
|
||||
import ConfirmDeleteModal from './confirm-delete-modal';
|
||||
import { useLpCategoriesSelection } from './lp-categories-selection-context';
|
||||
import type { LpCategory } from './type';
|
||||
import { useLpCategoriesSelection } from './mf-categories-selection-context';
|
||||
import type { MfCategory } from './type';
|
||||
|
||||
function columns(handleDeleteClick: (testId: string) => void): ColumnDef<LpCategory>[] {
|
||||
function columns(handleDeleteClick: (testId: string) => void): ColumnDef<MfCategory>[] {
|
||||
return [
|
||||
{
|
||||
formatter: (row): React.JSX.Element => (
|
||||
@@ -40,7 +40,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<LpCateg
|
||||
<Link
|
||||
color="inherit"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.lp_categories.details(row.id)}
|
||||
href={paths.dashboard.mf_categories.details(row.id)}
|
||||
sx={{ whiteSpace: 'nowrap' }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
@@ -163,7 +163,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<LpCateg
|
||||
//
|
||||
color="secondary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.lp_categories.details(row.id)}
|
||||
href={paths.dashboard.mf_categories.details(row.id)}
|
||||
>
|
||||
<PencilSimpleIcon size={24} />
|
||||
</LoadingButton>
|
||||
@@ -187,11 +187,11 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<LpCateg
|
||||
}
|
||||
|
||||
export interface LessonCategoriesTableProps {
|
||||
rows: LpCategory[];
|
||||
rows: MfCategory[];
|
||||
reloadRows: () => void;
|
||||
}
|
||||
|
||||
export function LpCategoriesTable({ rows, reloadRows }: LessonCategoriesTableProps): React.JSX.Element {
|
||||
export function MfCategoriesTable({ rows, reloadRows }: LessonCategoriesTableProps): React.JSX.Element {
|
||||
const { t } = useTranslation(['lp_categories']);
|
||||
const { deselectAll, deselectOne, selectAll, selectOne, selected } = useLpCategoriesSelection();
|
||||
|
||||
@@ -211,7 +211,7 @@ export function LpCategoriesTable({ rows, reloadRows }: LessonCategoriesTablePro
|
||||
reloadRows={reloadRows}
|
||||
setOpen={setOpen}
|
||||
/>
|
||||
<DataTable<LpCategory>
|
||||
<DataTable<MfCategory>
|
||||
columns={columns(handleDeleteClick)}
|
||||
onDeselectAll={deselectAll}
|
||||
onDeselectOne={(_, row) => {
|
@@ -4,7 +4,7 @@ import * as React from 'react';
|
||||
import RouterLink from 'next/link';
|
||||
import { useParams, useRouter } from 'next/navigation';
|
||||
//
|
||||
import { COL_QUIZ_LP_CATEGORIES } from '@/constants';
|
||||
import { COL_QUIZ_MF_CATEGORIES } from '@/constants';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { LoadingButton } from '@mui/lab';
|
||||
//
|
||||
@@ -88,7 +88,7 @@ const defaultValues = {
|
||||
description: '',
|
||||
} satisfies Values;
|
||||
|
||||
export function LpCategoryEditForm(): React.JSX.Element {
|
||||
export function MfCategoryEditForm(): React.JSX.Element {
|
||||
const router = useRouter();
|
||||
const { t } = useTranslation(['lp_categories']);
|
||||
|
||||
@@ -129,10 +129,10 @@ export function LpCategoryEditForm(): React.JSX.Element {
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await pb.collection(COL_QUIZ_LP_CATEGORIES).update(catId, tempUpdate);
|
||||
const result = await pb.collection(COL_QUIZ_MF_CATEGORIES).update(catId, tempUpdate);
|
||||
logger.debug(result);
|
||||
toast.success(t('edit.success'));
|
||||
router.push(paths.dashboard.lp_categories.list);
|
||||
router.push(paths.dashboard.mf_categories.list);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
toast.error(t('update.failed'));
|
||||
@@ -171,7 +171,7 @@ export function LpCategoryEditForm(): React.JSX.Element {
|
||||
setShowLoading(true);
|
||||
|
||||
try {
|
||||
const result = await pb.collection(COL_QUIZ_LP_CATEGORIES).getOne(id);
|
||||
const result = await pb.collection(COL_QUIZ_MF_CATEGORIES).getOne(id);
|
||||
|
||||
reset({ ...defaultValues, ...result, init_answer: JSON.stringify(result.init_answer) });
|
||||
setTextDescription(result.description);
|
||||
@@ -480,7 +480,7 @@ export function LpCategoryEditForm(): React.JSX.Element {
|
||||
<Button
|
||||
color="secondary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.lp_categories.list}
|
||||
href={paths.dashboard.mf_categories.list}
|
||||
>
|
||||
{t('edit.cancelButton')}
|
||||
</Button>
|
@@ -1,4 +1,4 @@
|
||||
export interface LpCategory {
|
||||
export interface MfCategory {
|
||||
isEmpty?: boolean;
|
||||
//
|
||||
id: string;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
import { dayjs } from '@/lib/dayjs';
|
||||
|
||||
import { CreateFormProps, LpQuestion } from './type';
|
||||
import { CreateFormProps, MfQuestion } from './type';
|
||||
|
||||
export const defaultLpQuestion: LpQuestion = {
|
||||
export const defaultMfQuestion: MfQuestion = {
|
||||
isEmpty: false,
|
||||
id: 'default-id',
|
||||
cat_name: 'default-question-name',
|
||||
@@ -38,7 +38,7 @@ export const defaultLpQuestion: LpQuestion = {
|
||||
// imageUrl: '',
|
||||
// };
|
||||
|
||||
export const emptyLpQuestion: LpQuestion = {
|
||||
...defaultLpQuestion,
|
||||
export const emptyLpQuestion: MfQuestion = {
|
||||
...defaultMfQuestion,
|
||||
isEmpty: true,
|
||||
};
|
||||
|
@@ -3,7 +3,7 @@
|
||||
import * as React from 'react';
|
||||
import RouterLink from 'next/link';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { COL_QUIZ_LP_CATEGORIES } from '@/constants';
|
||||
import { COL_QUIZ_MF_CATEGORIES } from '@/constants';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { LoadingButton } from '@mui/lab';
|
||||
import { Avatar, Divider, MenuItem, Select } from '@mui/material';
|
||||
@@ -66,7 +66,7 @@ export const defaultValues = {
|
||||
description: '',
|
||||
} satisfies Values;
|
||||
|
||||
export function LpQuestionCreateForm(): React.JSX.Element {
|
||||
export function MfQuestionCreateForm(): React.JSX.Element {
|
||||
const router = useRouter();
|
||||
const { t } = useTranslation(['lp_categories']);
|
||||
|
||||
@@ -101,11 +101,11 @@ export function LpQuestionCreateForm(): React.JSX.Element {
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await pb.collection(COL_QUIZ_LP_CATEGORIES).create(payload);
|
||||
const result = await pb.collection(COL_QUIZ_MF_CATEGORIES).create(payload);
|
||||
|
||||
logger.debug(result);
|
||||
toast.success(t('create.success'));
|
||||
router.push(paths.dashboard.lp_categories.list);
|
||||
router.push(paths.dashboard.mf_categories.list);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
toast.error(t('create.failed'));
|
@@ -4,7 +4,7 @@ import * as React from 'react';
|
||||
import RouterLink from 'next/link';
|
||||
import { useParams, useRouter } from 'next/navigation';
|
||||
//
|
||||
import { COL_QUIZ_LP_CATEGORIES } from '@/constants';
|
||||
import { COL_QUIZ_MF_CATEGORIES } from '@/constants';
|
||||
import { zodResolver } from '@hookform/resolvers/zod';
|
||||
import { LoadingButton } from '@mui/lab';
|
||||
//
|
||||
@@ -88,7 +88,7 @@ const defaultValues = {
|
||||
description: '',
|
||||
} satisfies Values;
|
||||
|
||||
export function LpQuestionEditForm(): React.JSX.Element {
|
||||
export function MfQuestionEditForm(): React.JSX.Element {
|
||||
const router = useRouter();
|
||||
const { t } = useTranslation(['lp_categories']);
|
||||
|
||||
@@ -129,10 +129,10 @@ export function LpQuestionEditForm(): React.JSX.Element {
|
||||
};
|
||||
|
||||
try {
|
||||
const result = await pb.collection(COL_QUIZ_LP_CATEGORIES).update(catId, tempUpdate);
|
||||
const result = await pb.collection(COL_QUIZ_MF_CATEGORIES).update(catId, tempUpdate);
|
||||
logger.debug(result);
|
||||
toast.success(t('edit.success'));
|
||||
router.push(paths.dashboard.lp_categories.list);
|
||||
router.push(paths.dashboard.mf_categories.list);
|
||||
} catch (error) {
|
||||
logger.error(error);
|
||||
toast.error(t('update.failed'));
|
||||
@@ -171,7 +171,7 @@ export function LpQuestionEditForm(): React.JSX.Element {
|
||||
setShowLoading(true);
|
||||
|
||||
try {
|
||||
const result = await pb.collection(COL_QUIZ_LP_CATEGORIES).getOne(id);
|
||||
const result = await pb.collection(COL_QUIZ_MF_CATEGORIES).getOne(id);
|
||||
|
||||
reset({ ...defaultValues, ...result, init_answer: JSON.stringify(result.init_answer) });
|
||||
setTextDescription(result.description);
|
||||
@@ -480,7 +480,7 @@ export function LpQuestionEditForm(): React.JSX.Element {
|
||||
<Button
|
||||
color="secondary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.lp_categories.list}
|
||||
href={paths.dashboard.mf_categories.list}
|
||||
>
|
||||
{t('edit.cancelButton')}
|
||||
</Button>
|
@@ -23,8 +23,8 @@ import { paths } from '@/paths';
|
||||
import { FilterButton, FilterPopover, useFilterContext } from '@/components/core/filter-button';
|
||||
import { Option } from '@/components/core/option';
|
||||
|
||||
import { useLpQuestionsSelection } from './lp-questions-selection-context';
|
||||
import { LpQuestion } from './type';
|
||||
import { useLpQuestionsSelection } from './mf-questions-selection-context';
|
||||
import { MfQuestion } from './type';
|
||||
|
||||
export interface Filters {
|
||||
email?: string;
|
||||
@@ -40,10 +40,10 @@ export type SortDir = 'asc' | 'desc';
|
||||
export interface LpQuestionsFiltersProps {
|
||||
filters?: Filters;
|
||||
sortDir?: SortDir;
|
||||
fullData: LpQuestion[];
|
||||
fullData: MfQuestion[];
|
||||
}
|
||||
|
||||
export function LpQuestionsFilters({
|
||||
export function MfQuestionsFilters({
|
||||
filters = {},
|
||||
sortDir = 'desc',
|
||||
fullData,
|
||||
@@ -60,13 +60,13 @@ export function LpQuestionsFilters({
|
||||
const selection = useLpQuestionsSelection();
|
||||
|
||||
function getVisible(): number {
|
||||
return fullData.reduce((count, item: LpQuestion) => {
|
||||
return fullData.reduce((count, item: MfQuestion) => {
|
||||
return item.visible === 'visible' ? count + 1 : count;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
function getHidden(): number {
|
||||
return fullData.reduce((count, item: LpQuestion) => {
|
||||
return fullData.reduce((count, item: MfQuestion) => {
|
||||
return item.visible === 'hidden' ? count + 1 : count;
|
||||
}, 0);
|
||||
}
|
@@ -16,7 +16,7 @@ interface LessonQuestionsPaginationProps {
|
||||
rowsPerPage: number;
|
||||
}
|
||||
|
||||
export function LpQuestionsPagination({
|
||||
export function MfQuestionsPagination({
|
||||
count,
|
||||
page,
|
||||
//
|
@@ -6,7 +6,7 @@ import * as React from 'react';
|
||||
import { useSelection } from '@/hooks/use-selection';
|
||||
import type { Selection } from '@/hooks/use-selection';
|
||||
|
||||
import type { LpQuestion } from './type';
|
||||
import type { MfQuestion } from './type';
|
||||
|
||||
function noop(): void {
|
||||
return undefined;
|
||||
@@ -26,14 +26,14 @@ export const LpQuestionsSelectionContext = React.createContext<LpQuestionsSelect
|
||||
|
||||
interface LpQuestionsSelectionProviderProps {
|
||||
children: React.ReactNode;
|
||||
lessonCategories: LpQuestion[];
|
||||
lessonQuestions: MfQuestion[];
|
||||
}
|
||||
|
||||
export function LpQuestionsSelectionProvider({
|
||||
export function MfQuestionsSelectionProvider({
|
||||
children,
|
||||
lessonCategories = [],
|
||||
lessonQuestions = [],
|
||||
}: LpQuestionsSelectionProviderProps): React.JSX.Element {
|
||||
const customerIds = React.useMemo(() => lessonCategories.map((customer) => customer.id), [lessonCategories]);
|
||||
const customerIds = React.useMemo(() => lessonQuestions.map((customer) => customer.id), [lessonQuestions]);
|
||||
const selection = useSelection(customerIds);
|
||||
|
||||
return (
|
@@ -25,10 +25,10 @@ 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';
|
||||
import { useLpQuestionsSelection } from './mf-questions-selection-context';
|
||||
import type { MfQuestion } from './type';
|
||||
|
||||
function columns(handleDeleteClick: (testId: string) => void): ColumnDef<LpQuestion>[] {
|
||||
function columns(handleDeleteClick: (testId: string) => void): ColumnDef<MfQuestion>[] {
|
||||
return [
|
||||
{
|
||||
formatter: (row): React.JSX.Element => (
|
||||
@@ -40,7 +40,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<LpQuest
|
||||
<Link
|
||||
color="inherit"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.lp_categories.details(row.id)}
|
||||
href={paths.dashboard.mf_categories.details(row.id)}
|
||||
sx={{ whiteSpace: 'nowrap' }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
@@ -163,7 +163,7 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<LpQuest
|
||||
//
|
||||
color="secondary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.lp_categories.details(row.id)}
|
||||
href={paths.dashboard.mf_categories.details(row.id)}
|
||||
>
|
||||
<PencilSimpleIcon size={24} />
|
||||
</LoadingButton>
|
||||
@@ -187,11 +187,11 @@ function columns(handleDeleteClick: (testId: string) => void): ColumnDef<LpQuest
|
||||
}
|
||||
|
||||
export interface LessonQuestionsTableProps {
|
||||
rows: LpQuestion[];
|
||||
rows: MfQuestion[];
|
||||
reloadRows: () => void;
|
||||
}
|
||||
|
||||
export function LpQuestionsTable({ rows, reloadRows }: LessonQuestionsTableProps): React.JSX.Element {
|
||||
export function MfQuestionsTable({ rows, reloadRows }: LessonQuestionsTableProps): React.JSX.Element {
|
||||
const { t } = useTranslation(['lp_categories']);
|
||||
const { deselectAll, deselectOne, selectAll, selectOne, selected } = useLpQuestionsSelection();
|
||||
|
||||
@@ -211,7 +211,7 @@ export function LpQuestionsTable({ rows, reloadRows }: LessonQuestionsTableProps
|
||||
reloadRows={reloadRows}
|
||||
setOpen={setOpen}
|
||||
/>
|
||||
<DataTable<LpQuestion>
|
||||
<DataTable<MfQuestion>
|
||||
columns={columns(handleDeleteClick)}
|
||||
onDeselectAll={deselectAll}
|
||||
onDeselectOne={(_, row) => {
|
@@ -1,4 +1,4 @@
|
||||
export interface LpQuestion {
|
||||
export interface MfQuestion {
|
||||
isEmpty?: boolean;
|
||||
//
|
||||
id: string;
|
||||
|
Reference in New Issue
Block a user