update,
This commit is contained in:
5
002_source/cms/src/app/dashboard/lesson_types/db.ts
Normal file
5
002_source/cms/src/app/dashboard/lesson_types/db.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import PocketBase, { RecordModel } from 'pocketbase';
|
||||
|
||||
export function Helloworld(): string {
|
||||
return 'helloworld';
|
||||
}
|
@@ -9,12 +9,15 @@ import Divider from '@mui/material/Divider';
|
||||
import Stack from '@mui/material/Stack';
|
||||
import Typography from '@mui/material/Typography';
|
||||
import { Plus as PlusIcon } from '@phosphor-icons/react/dist/ssr/Plus';
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
import PocketBase from 'pocketbase';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { paths } from '@/paths';
|
||||
import { logger } from '@/lib/default-logger';
|
||||
import { toast } from '@/components/core/toaster';
|
||||
import type { LessonType } from '@/components/dashboard/lesson_type/ILessonType';
|
||||
import { safeAssignment } from '@/components/dashboard/lesson_type/interfaces';
|
||||
import { LessonTypesFilters } from '@/components/dashboard/lesson_type/lesson-types-filters';
|
||||
import type { Filters } from '@/components/dashboard/lesson_type/lesson-types-filters';
|
||||
import { LessonTypesPagination } from '@/components/dashboard/lesson_type/lesson-types-pagination';
|
||||
@@ -22,46 +25,55 @@ import { LessonTypesSelectionProvider } from '@/components/dashboard/lesson_type
|
||||
import { LessonTypesTable } from '@/components/dashboard/lesson_type/lesson-types-table';
|
||||
import FormLoading from '@/components/loading';
|
||||
|
||||
import { Helloworld } from './db';
|
||||
|
||||
const pb = new PocketBase(process.env.NEXT_PUBLIC_POCKETBASE_URL);
|
||||
|
||||
interface PageProps {
|
||||
searchParams: {
|
||||
email?: string;
|
||||
phone?: string;
|
||||
sortDir?: 'asc' | 'desc';
|
||||
status?: string;
|
||||
name?: string;
|
||||
visible?: string;
|
||||
type?: string;
|
||||
spStatus?: string;
|
||||
spName?: string;
|
||||
spVisible?: string;
|
||||
spType?: string;
|
||||
//
|
||||
};
|
||||
}
|
||||
|
||||
export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const { email, phone, sortDir, status, name, visible, type } = searchParams;
|
||||
const { email, phone, sortDir, spStatus, spName, spVisible, spType } = searchParams;
|
||||
const router = useRouter();
|
||||
|
||||
const [isLoadingAddPage, setIsLoadingAddPage] = React.useState<boolean>(false);
|
||||
const [lessonTypesData, setLessonTypesData] = React.useState<LessonType[]>([]);
|
||||
// const [recordModel, setRecordModel] = React.useState<RecordModel[]>([]);
|
||||
const sortedLessonTypes = applySort(lessonTypesData, sortDir);
|
||||
const filteredLessonTypes = applyFilters(sortedLessonTypes, {
|
||||
email,
|
||||
phone,
|
||||
status,
|
||||
name,
|
||||
type,
|
||||
visible,
|
||||
spStatus,
|
||||
spName,
|
||||
spType,
|
||||
spVisible,
|
||||
//
|
||||
});
|
||||
|
||||
const reloadRows = () => {
|
||||
// listLessonTypes()
|
||||
// .then((lessonTypes: LessonType[]) => {
|
||||
// setLessonTypesData(lessonTypes);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// logger.error(err);
|
||||
// toast(t('dashboard.lessonTypes.list.error'));
|
||||
// });
|
||||
pb.collection('LessonsTypes')
|
||||
.getFullList()
|
||||
.then((lessonTypes: RecordModel[]) => {
|
||||
const tempLessonTypes: LessonType[] = lessonTypes.map((lt) => {
|
||||
return safeAssignment(lt);
|
||||
});
|
||||
setLessonTypesData(tempLessonTypes);
|
||||
})
|
||||
.catch((err) => {
|
||||
logger.error(err);
|
||||
toast(t('dashboard.lessonTypes.list.error'));
|
||||
});
|
||||
};
|
||||
|
||||
React.useEffect(() => {
|
||||
@@ -102,7 +114,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
||||
<LessonTypesSelectionProvider lessonTypes={filteredLessonTypes}>
|
||||
<Card>
|
||||
<LessonTypesFilters
|
||||
filters={{ email, phone, status, name, visible, type }}
|
||||
filters={{ email, phone, spStatus, spName, spVisible, spType }}
|
||||
fullData={lessonTypesData}
|
||||
sortDir={sortDir}
|
||||
/>
|
||||
@@ -131,7 +143,10 @@ function applySort(row: LessonType[], sortDir: 'asc' | 'desc' | undefined): Less
|
||||
});
|
||||
}
|
||||
|
||||
function applyFilters(row: LessonType[], { email, phone, status, name, visible }: Filters): LessonType[] {
|
||||
function applyFilters(
|
||||
row: LessonType[],
|
||||
{ email, phone, spStatus: status, spName: name, spVisible: visible }: Filters
|
||||
): LessonType[] {
|
||||
return row.filter((item) => {
|
||||
if (email) {
|
||||
if (!item.email?.toLowerCase().includes(email.toLowerCase())) {
|
||||
|
Reference in New Issue
Block a user