update,
This commit is contained in:
@@ -9,7 +9,6 @@ import { useRouter } from 'next/navigation';
|
||||
import { COL_TEACHERS } from '@/constants';
|
||||
import { LoadingButton } from '@mui/lab';
|
||||
import Box from '@mui/material/Box';
|
||||
import Button from '@mui/material/Button';
|
||||
import Card from '@mui/material/Card';
|
||||
import Divider from '@mui/material/Divider';
|
||||
import Stack from '@mui/material/Stack';
|
||||
@@ -17,21 +16,17 @@ import Typography from '@mui/material/Typography';
|
||||
import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus';
|
||||
import type { ListResult, RecordModel } from 'pocketbase';
|
||||
|
||||
import { config } from '@/config';
|
||||
import { TeachersFilters } from '@/components/dashboard/teacher/teachers-filters';
|
||||
// import type { Filters } from '@/components/dashboard/teacher/customers-filters';
|
||||
import { TeachersPagination } from '@/components/dashboard/teacher/teachers-pagination';
|
||||
import { TeachersSelectionProvider } from '@/components/dashboard/teacher/teachers-selection-context';
|
||||
import { TeachersTable } from '@/components/dashboard/teacher/teachers-table';
|
||||
import type { Teacher, Filters } from '@/components/dashboard/teacher/type.d';
|
||||
import { SampleTeachers } from './SampleTeachers';
|
||||
import type { Teacher } from '@/components/dashboard/teacher/type.d';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { paths } from '@/paths';
|
||||
import isDevelopment from '@/lib/check-is-development';
|
||||
import { logger } from '@/lib/default-logger';
|
||||
import { pb } from '@/lib/pb';
|
||||
import { toast } from '@/components/core/toaster';
|
||||
import ErrorDisplay from '@/components/dashboard/error';
|
||||
import { defaultTeacher } from '@/components/dashboard/teacher/_constants';
|
||||
import FormLoading from '@/components/loading';
|
||||
@@ -112,6 +107,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
if (email) {
|
||||
tempFilter.push(`email ~ "%${email}%"`);
|
||||
}
|
||||
|
||||
if (phone) {
|
||||
tempFilter.push(`phone ~ "%${phone}%"`);
|
||||
}
|
||||
|
@@ -21,11 +21,9 @@ import { paths } from '@/paths';
|
||||
import isDevelopment from '@/lib/check-is-development';
|
||||
import { logger } from '@/lib/default-logger';
|
||||
import { pb } from '@/lib/pb';
|
||||
// import { toast } from '@/components/core/toaster';
|
||||
import ErrorDisplay from '@/components/dashboard/error';
|
||||
import { defaultVocabulary } from '@/components/dashboard/vocabulary/_constants';
|
||||
import { VocabulariesFilters } from '@/components/dashboard/vocabulary/vocabularies-filters';
|
||||
import type { Filters } from '@/components/dashboard/vocabulary/vocabularies-filters';
|
||||
import { VocabulariesPagination } from '@/components/dashboard/vocabulary/vocabularies-pagination';
|
||||
import { VocabulariesSelectionProvider } from '@/components/dashboard/vocabulary/vocabularies-selection-context';
|
||||
import { VocabulariesTable } from '@/components/dashboard/vocabulary/vocabularies-table';
|
||||
@@ -36,7 +34,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const router = useRouter();
|
||||
|
||||
const { email, phone, sortDir, status, name, visible, type } = searchParams;
|
||||
const { email, phone, sortDir, status, name, visible, type, word, category } = searchParams;
|
||||
|
||||
const [lessonCategoriesData, setLessonCategoriesData] = React.useState<Vocabulary[]>([]);
|
||||
|
||||
@@ -118,6 +116,14 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
tempFilter.push(`type ~ "%${type}%"`);
|
||||
}
|
||||
|
||||
if (word) {
|
||||
tempFilter.push(`word ~ "%${word}%"`);
|
||||
}
|
||||
|
||||
if (category) {
|
||||
tempFilter.push(`cat_id ~ "%000000000000003%"`);
|
||||
}
|
||||
|
||||
let preFinalListOption = {};
|
||||
if (tempFilter.length > 0) {
|
||||
preFinalListOption = { filter: tempFilter.join(' && ') };
|
||||
@@ -126,7 +132,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
preFinalListOption = { ...preFinalListOption, sort: tempSortDir };
|
||||
}
|
||||
setListOption(preFinalListOption);
|
||||
}, [visible, sortDir, name, type]);
|
||||
}, [visible, sortDir, name, type, word, category]);
|
||||
|
||||
// return <>helloworld</>;
|
||||
|
||||
@@ -136,7 +142,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
return (
|
||||
<ErrorDisplay
|
||||
message={t('error.unable-to-process-request')}
|
||||
code="500"
|
||||
code={-1}
|
||||
details={showError.detail}
|
||||
/>
|
||||
);
|
||||
@@ -177,7 +183,8 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
<VocabulariesSelectionProvider lessonCategories={f}>
|
||||
<Card>
|
||||
<VocabulariesFilters
|
||||
filters={{ email, phone, status, name, visible, type }}
|
||||
// category
|
||||
filters={{ email, phone, status, name, visible, type, word, category }}
|
||||
fullData={lessonCategoriesData}
|
||||
sortDir={sortDir}
|
||||
/>
|
||||
@@ -206,62 +213,16 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
);
|
||||
}
|
||||
|
||||
// Sorting and filtering has to be done on the server.
|
||||
|
||||
// function applySort(row: Vocabulary[], sortDir: 'asc' | 'desc' | undefined): Vocabulary[] {
|
||||
// return row.sort((a, b) => {
|
||||
// if (sortDir === 'asc') {
|
||||
// return a.createdAt.getTime() - b.createdAt.getTime();
|
||||
// }
|
||||
|
||||
// return b.createdAt.getTime() - a.createdAt.getTime();
|
||||
// });
|
||||
// }
|
||||
|
||||
// function applyFilters(row: Vocabulary[], { email, phone, status, name, visible }: Filters): Vocabulary[] {
|
||||
// return row.filter((item) => {
|
||||
// if (email) {
|
||||
// if (!item.email?.toLowerCase().includes(email.toLowerCase())) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (phone) {
|
||||
// if (!item.phone?.toLowerCase().includes(phone.toLowerCase())) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (status) {
|
||||
// if (item.status !== status) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (name) {
|
||||
// if (!item.name?.toLowerCase().includes(name.toLowerCase())) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (visible) {
|
||||
// if (!item.visible?.toLowerCase().includes(visible.toLowerCase())) {
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return true;
|
||||
// });
|
||||
// }
|
||||
|
||||
interface PageProps {
|
||||
searchParams: {
|
||||
email?: string;
|
||||
phone?: string;
|
||||
sortDir?: 'asc' | 'desc';
|
||||
status?: string;
|
||||
word?: string;
|
||||
name?: string;
|
||||
visible?: string;
|
||||
type?: string;
|
||||
category?: string;
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user