update, in the middle,
This commit is contained in:
@@ -7,7 +7,7 @@ import SampleAddressCard from '@/app/dashboard/Sample/AddressCard';
|
||||
import { SampleNotifications } from '@/app/dashboard/Sample/Notifications';
|
||||
import SamplePaymentCard from '@/app/dashboard/Sample/PaymentCard';
|
||||
import SampleSecurityCard from '@/app/dashboard/Sample/SecurityCard';
|
||||
import { COL_QUIZ_LP_QUESTIONS } from '@/constants';
|
||||
import { COL_QUIZ_CR_QUESTIONS } from '@/constants';
|
||||
import { Grid } from '@mui/material';
|
||||
import Box from '@mui/material/Box';
|
||||
import Link from '@mui/material/Link';
|
||||
@@ -21,9 +21,9 @@ import { logger } from '@/lib/default-logger';
|
||||
import { pb } from '@/lib/pb';
|
||||
import { toast } from '@/components/core/toaster';
|
||||
import ErrorDisplay from '@/components/dashboard/error';
|
||||
import { defaultLpQuestion } from '@/components/dashboard/lp/questions/_constants.ts';
|
||||
import { Notifications } from '@/components/dashboard/lp/questions/notifications';
|
||||
import type { LpQuestion } from '@/components/dashboard/lp/questions/type';
|
||||
import { defaultCrQuestion } from '@/components/dashboard/cr/questions/_constants.ts';
|
||||
import { Notifications } from '@/components/dashboard/cr/questions/notifications';
|
||||
import type { CrQuestion } from '@/components/dashboard/cr/questions/type';
|
||||
import FormLoading from '@/components/loading';
|
||||
|
||||
import BasicDetailCard from './BasicDetailCard';
|
||||
@@ -39,18 +39,18 @@ export default function Page(): React.JSX.Element {
|
||||
const [showError, setShowError] = React.useState({ show: false, detail: '' });
|
||||
|
||||
//
|
||||
const [showLessonQuestion, setShowLessonQuestion] = React.useState<LpQuestion>(defaultLpQuestion);
|
||||
const [showLessonQuestion, setShowLessonQuestion] = React.useState<CrQuestion>(defaultCrQuestion);
|
||||
|
||||
function handleEditClick() {
|
||||
router.push(paths.dashboard.lp_questions.edit(showLessonQuestion.id));
|
||||
router.push(paths.dashboard.cr_questions.edit(showLessonQuestion.id));
|
||||
}
|
||||
|
||||
React.useEffect(() => {
|
||||
if (catId) {
|
||||
pb.collection(COL_QUIZ_LP_QUESTIONS)
|
||||
pb.collection(COL_QUIZ_CR_QUESTIONS)
|
||||
.getOne(catId)
|
||||
.then((model: RecordModel) => {
|
||||
setShowLessonQuestion({ ...defaultLpQuestion, ...model });
|
||||
setShowLessonQuestion({ ...defaultCrQuestion, ...model });
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error(err);
|
||||
@@ -89,7 +89,7 @@ export default function Page(): React.JSX.Element {
|
||||
<Link
|
||||
color="text.primary"
|
||||
component={RouterLink}
|
||||
href={paths.dashboard.lp_questions.list}
|
||||
href={paths.dashboard.cr_questions.list}
|
||||
sx={{ alignItems: 'center', display: 'inline-flex', gap: 1 }}
|
||||
variant="subtitle2"
|
||||
>
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { dayjs } from '@/lib/dayjs';
|
||||
import { LessonCategory } from '@/components/dashboard/lesson_category/type';
|
||||
|
||||
export const LpCategoriesSampleData = [
|
||||
export const CrCategoriesSampleData = [
|
||||
{
|
||||
id: 'USR-005',
|
||||
name: 'Fran Perez',
|
@@ -13,7 +13,7 @@ import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/Arrow
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { paths } from '@/paths';
|
||||
import { LpQuestionCreateForm } from '@/components/dashboard/lp/questions/lp-question-create-form';
|
||||
import { CrQuestionCreateForm } from '@/components/dashboard/cr/questions/cr-question-create-form';
|
||||
|
||||
export default function Page(): React.JSX.Element {
|
||||
// RULES: follow the name of page directory
|
||||
@@ -46,7 +46,7 @@ export default function Page(): React.JSX.Element {
|
||||
<Typography variant="h4">{t('create.title')}</Typography>
|
||||
</div>
|
||||
</Stack>
|
||||
<LpQuestionCreateForm />
|
||||
<CrQuestionCreateForm />
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
|
@@ -10,7 +10,7 @@ import { ArrowLeft as ArrowLeftIcon } from '@phosphor-icons/react/dist/ssr/Arrow
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { paths } from '@/paths';
|
||||
import { LpQuestionEditForm } from '@/components/dashboard/lp/questions/lp-question-edit-form';
|
||||
import { CrQuestionEditForm } from '@/components/dashboard/cr/questions/cr-question-edit-form';
|
||||
|
||||
export default function Page(): React.JSX.Element {
|
||||
const { t } = useTranslation(['lp_questions']);
|
||||
@@ -46,7 +46,7 @@ export default function Page(): React.JSX.Element {
|
||||
<Typography variant="h4">{t('edit.title')}</Typography>
|
||||
</div>
|
||||
</Stack>
|
||||
<LpQuestionEditForm />
|
||||
<CrQuestionEditForm />
|
||||
</Stack>
|
||||
</Box>
|
||||
);
|
||||
|
@@ -1,12 +1,12 @@
|
||||
'use client';
|
||||
|
||||
// RULES:
|
||||
// contains list page for lp_questions (QuizLPQuestions)
|
||||
// contains list page for cr_questions (QuizCRQuestions)
|
||||
// contain definition to collection only
|
||||
//
|
||||
import * as React from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { COL_QUIZ_LP_QUESTIONS } from '@/constants';
|
||||
import { COL_QUIZ_CR_QUESTIONS } from '@/constants';
|
||||
import { LoadingButton } from '@mui/lab';
|
||||
import Box from '@mui/material/Box';
|
||||
import Card from '@mui/material/Card';
|
||||
@@ -23,20 +23,20 @@ import { logger } from '@/lib/default-logger';
|
||||
import { pb } from '@/lib/pb';
|
||||
import { toast } from '@/components/core/toaster';
|
||||
import ErrorDisplay from '@/components/dashboard/error';
|
||||
import { defaultLpQuestion } from '@/components/dashboard/lp/questions/_constants';
|
||||
import { LpQuestionsFilters } from '@/components/dashboard/lp/questions/lp-questions-filters';
|
||||
import type { Filters } from '@/components/dashboard/lp/questions/lp-questions-filters';
|
||||
import { LpQuestionsPagination } from '@/components/dashboard/lp/questions/lp-questions-pagination';
|
||||
import { LpQuestionsSelectionProvider } from '@/components/dashboard/lp/questions/lp-questions-selection-context';
|
||||
import { LpQuestionsTable } from '@/components/dashboard/lp/questions/lp-questions-table';
|
||||
import type { LpQuestion } from '@/components/dashboard/lp/questions/type';
|
||||
import { defaultCrQuestion } from '@/components/dashboard/cr/questions/_constants';
|
||||
import { CrQuestionsFilters } from '@/components/dashboard/cr/questions/cr-questions-filters';
|
||||
import type { Filters } from '@/components/dashboard/cr/questions/cr-questions-filters';
|
||||
import { CrQuestionsPagination } from '@/components/dashboard/cr/questions/cr-questions-pagination';
|
||||
import { CrQuestionsSelectionProvider } from '@/components/dashboard/cr/questions/cr-questions-selection-context';
|
||||
import { CrQuestionsTable } from '@/components/dashboard/cr/questions/cr-questions-table';
|
||||
import type { CrQuestion } from '@/components/dashboard/cr/questions/type';
|
||||
import FormLoading from '@/components/loading';
|
||||
|
||||
export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
const { t } = useTranslation(['lp_questions']);
|
||||
const { email, phone, sortDir, status, name, visible, type } = searchParams;
|
||||
const router = useRouter();
|
||||
const [lessonQuestionsData, setLessonCategoriesData] = React.useState<LpQuestion[]>([]);
|
||||
const [lessonQuestionsData, setLessonCategoriesData] = React.useState<CrQuestion[]>([]);
|
||||
//
|
||||
|
||||
const [isLoadingAddPage, setIsLoadingAddPage] = React.useState<boolean>(false);
|
||||
@@ -45,7 +45,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
//
|
||||
const [rowsPerPage, setRowsPerPage] = React.useState<number>(5);
|
||||
//
|
||||
const [f, setF] = React.useState<LpQuestion[]>([]);
|
||||
const [f, setF] = React.useState<CrQuestion[]>([]);
|
||||
const [currentPage, setCurrentPage] = React.useState<number>(0);
|
||||
//
|
||||
const [recordCount, setRecordCount] = React.useState<number>(0);
|
||||
@@ -59,11 +59,11 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
const reloadRows = async (): Promise<void> => {
|
||||
try {
|
||||
const models: ListResult<RecordModel> = await pb
|
||||
.collection(COL_QUIZ_LP_QUESTIONS)
|
||||
.collection(COL_QUIZ_CR_QUESTIONS)
|
||||
.getList(currentPage + 1, rowsPerPage, listOption);
|
||||
const { items, totalItems } = models;
|
||||
const tempLessonTypes: LpQuestion[] = items.map((lt) => {
|
||||
return { ...defaultLpQuestion, ...lt };
|
||||
const tempLessonTypes: CrQuestion[] = items.map((lt) => {
|
||||
return { ...defaultCrQuestion, ...lt };
|
||||
});
|
||||
|
||||
setLessonCategoriesData(tempLessonTypes);
|
||||
@@ -88,15 +88,13 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
React.useEffect(() => {
|
||||
if (!isFirstRun.current) {
|
||||
isFirstRun.current = true;
|
||||
} else if (JSON.stringify(listOption) !== JSON.stringify(lastListOption)) {
|
||||
// reset page number as tab changes
|
||||
setLastListOption(listOption);
|
||||
setCurrentPage(0);
|
||||
void reloadRows();
|
||||
} else {
|
||||
if (JSON.stringify(listOption) !== JSON.stringify(lastListOption)) {
|
||||
// reset page number as tab changes
|
||||
setLastListOption(listOption);
|
||||
setCurrentPage(0);
|
||||
void reloadRows();
|
||||
} else {
|
||||
void reloadRows();
|
||||
}
|
||||
void reloadRows();
|
||||
}
|
||||
}, [currentPage, rowsPerPage, listOption]);
|
||||
|
||||
@@ -171,7 +169,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
loading={isLoadingAddPage}
|
||||
onClick={(): void => {
|
||||
setIsLoadingAddPage(true);
|
||||
router.push(paths.dashboard.lp_questions.create);
|
||||
router.push(paths.dashboard.cr_questions.create);
|
||||
}}
|
||||
startIcon={<PlusIcon />}
|
||||
variant="contained"
|
||||
@@ -180,22 +178,22 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
</LoadingButton>
|
||||
</Box>
|
||||
</Stack>
|
||||
<LpQuestionsSelectionProvider lessonQuestions={f}>
|
||||
<CrQuestionsSelectionProvider lessonQuestions={f}>
|
||||
<Card>
|
||||
<LpQuestionsFilters
|
||||
<CrQuestionsFilters
|
||||
filters={{ email, phone, status, name, visible, type }}
|
||||
fullData={lessonQuestionsData}
|
||||
sortDir={sortDir}
|
||||
/>
|
||||
<Divider />
|
||||
<Box sx={{ overflowX: 'auto' }}>
|
||||
<LpQuestionsTable
|
||||
<CrQuestionsTable
|
||||
reloadRows={reloadRows}
|
||||
rows={f}
|
||||
/>
|
||||
</Box>
|
||||
<Divider />
|
||||
<LpQuestionsPagination
|
||||
<CrQuestionsPagination
|
||||
count={recordCount}
|
||||
page={currentPage}
|
||||
rowsPerPage={rowsPerPage}
|
||||
@@ -203,7 +201,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
setRowsPerPage={setRowsPerPage}
|
||||
/>
|
||||
</Card>
|
||||
</LpQuestionsSelectionProvider>
|
||||
</CrQuestionsSelectionProvider>
|
||||
</Stack>
|
||||
<Box sx={{ display: isDevelopment ? 'block' : 'none' }}>
|
||||
<pre>{JSON.stringify(f, null, 2)}</pre>
|
||||
@@ -214,7 +212,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
|
||||
// Sorting and filtering has to be done on the server.
|
||||
|
||||
function applySort(row: LpQuestion[], sortDir: 'asc' | 'desc' | undefined): LpQuestion[] {
|
||||
function applySort(row: CrQuestion[], sortDir: 'asc' | 'desc' | undefined): CrQuestion[] {
|
||||
return row.sort((a, b) => {
|
||||
if (sortDir === 'asc') {
|
||||
return a.createdAt.getTime() - b.createdAt.getTime();
|
||||
@@ -224,7 +222,7 @@ function applySort(row: LpQuestion[], sortDir: 'asc' | 'desc' | undefined): LpQu
|
||||
});
|
||||
}
|
||||
|
||||
function applyFilters(row: LpQuestion[], { email, phone, status, name, visible }: Filters): LpQuestion[] {
|
||||
function applyFilters(row: CrQuestion[], { email, phone, status, name, visible }: Filters): CrQuestion[] {
|
||||
return row.filter((item) => {
|
||||
if (email) {
|
||||
if (!item.email?.toLowerCase().includes(email.toLowerCase())) {
|
||||
|
Reference in New Issue
Block a user