update,
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
import type { RecordModel } from 'pocketbase';
|
||||
|
||||
import { dayjs } from '@/lib/dayjs';
|
||||
|
||||
import type { LessonType } from './ILessonType';
|
||||
|
||||
export interface LessonTypeEditFormProps {
|
||||
name: string;
|
||||
type: string;
|
||||
@@ -23,3 +29,41 @@ export const LessonTypeCreateFormDefault: LessonTypeCreateForm = {
|
||||
pos: 1,
|
||||
visible: 'visible',
|
||||
};
|
||||
|
||||
export const defaultLessonType: LessonType = {
|
||||
id: 'string',
|
||||
name: 'string',
|
||||
type: 'string',
|
||||
pos: 1,
|
||||
visible: 'visible',
|
||||
createdAt: dayjs().toDate(),
|
||||
//
|
||||
// original
|
||||
// id: 'string',
|
||||
// name: 'string',
|
||||
//
|
||||
avatar: 'string',
|
||||
email: 'string',
|
||||
phone: 'string',
|
||||
quota: 1,
|
||||
status: 'pending',
|
||||
// createdAt: Date;
|
||||
};
|
||||
|
||||
export function safeAssignment(inTemp: LessonType | RecordModel): LessonType {
|
||||
const { id, name, type, pos, visible, createdAt, email, quota, status } = { ...defaultLessonType, ...inTemp };
|
||||
const oCreatedAt = dayjs(createdAt).toDate();
|
||||
|
||||
const output: LessonType = {
|
||||
id,
|
||||
name,
|
||||
type,
|
||||
pos,
|
||||
visible,
|
||||
createdAt: oCreatedAt,
|
||||
email,
|
||||
quota,
|
||||
status,
|
||||
};
|
||||
return output;
|
||||
}
|
||||
|
@@ -19,16 +19,16 @@ import { paths } from '@/paths';
|
||||
import { FilterButton, FilterPopover, useFilterContext } from '@/components/core/filter-button';
|
||||
import { Option } from '@/components/core/option';
|
||||
|
||||
import { LessonType } from './ILessonType';
|
||||
import type { LessonType } from './ILessonType';
|
||||
import { useLessonTypesSelection } from './lesson-types-selection-context';
|
||||
|
||||
export interface Filters {
|
||||
email?: string;
|
||||
phone?: string;
|
||||
status?: string;
|
||||
name?: string;
|
||||
visible?: string;
|
||||
type?: string;
|
||||
spStatus?: string;
|
||||
spName?: string;
|
||||
spVisible?: string;
|
||||
spType?: string;
|
||||
}
|
||||
|
||||
export type SortDir = 'asc' | 'desc';
|
||||
@@ -45,7 +45,7 @@ export function LessonTypesFilters({
|
||||
fullData,
|
||||
}: LessonTypesFiltersProps): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const { email, phone, status, name, visible, type } = filters;
|
||||
const { email, phone, spStatus: status, spName, spVisible, spType } = filters;
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
@@ -81,8 +81,8 @@ export function LessonTypesFilters({
|
||||
searchParams.set('sortDir', newSortDir);
|
||||
}
|
||||
|
||||
if (newFilters.status) {
|
||||
searchParams.set('status', newFilters.status);
|
||||
if (newFilters.spStatus) {
|
||||
searchParams.set('status', newFilters.spStatus);
|
||||
}
|
||||
|
||||
if (newFilters.email) {
|
||||
@@ -93,16 +93,16 @@ export function LessonTypesFilters({
|
||||
searchParams.set('phone', newFilters.phone);
|
||||
}
|
||||
|
||||
if (newFilters.name) {
|
||||
searchParams.set('name', newFilters.name);
|
||||
if (newFilters.spName) {
|
||||
searchParams.set('name', newFilters.spName);
|
||||
}
|
||||
|
||||
if (newFilters.type) {
|
||||
searchParams.set('type', newFilters.type);
|
||||
if (newFilters.spType) {
|
||||
searchParams.set('type', newFilters.spType);
|
||||
}
|
||||
|
||||
if (newFilters.visible) {
|
||||
searchParams.set('visible', newFilters.visible);
|
||||
if (newFilters.spVisible) {
|
||||
searchParams.set('visible', newFilters.spVisible);
|
||||
}
|
||||
|
||||
router.push(`${paths.dashboard.lesson_types.list}?${searchParams.toString()}`);
|
||||
@@ -116,28 +116,28 @@ export function LessonTypesFilters({
|
||||
|
||||
const handleStatusChange = React.useCallback(
|
||||
(_: React.SyntheticEvent, value: string) => {
|
||||
updateSearchParams({ ...filters, status: value }, sortDir);
|
||||
updateSearchParams({ ...filters, spStatus: value }, sortDir);
|
||||
},
|
||||
[updateSearchParams, filters, sortDir]
|
||||
);
|
||||
|
||||
const handleVisibleChange = React.useCallback(
|
||||
(_: React.SyntheticEvent, value: string) => {
|
||||
updateSearchParams({ ...filters, visible: value }, sortDir);
|
||||
updateSearchParams({ ...filters, spVisible: value }, sortDir);
|
||||
},
|
||||
[updateSearchParams, filters, sortDir]
|
||||
);
|
||||
|
||||
const handleNameChange = React.useCallback(
|
||||
(value?: string) => {
|
||||
updateSearchParams({ ...filters, name: value }, sortDir);
|
||||
updateSearchParams({ ...filters, spName: value }, sortDir);
|
||||
},
|
||||
[updateSearchParams, filters, sortDir]
|
||||
);
|
||||
|
||||
const handleTypeChange = React.useCallback(
|
||||
(value?: string) => {
|
||||
updateSearchParams({ ...filters, type: value }, sortDir);
|
||||
updateSearchParams({ ...filters, spType: value }, sortDir);
|
||||
},
|
||||
[updateSearchParams, filters, sortDir]
|
||||
);
|
||||
@@ -163,11 +163,11 @@ export function LessonTypesFilters({
|
||||
[updateSearchParams, filters]
|
||||
);
|
||||
|
||||
const hasFilters = status || email || phone || visible || name || type;
|
||||
const hasFilters = status || email || phone || spVisible || spName || spType;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Tabs onChange={handleVisibleChange} sx={{ px: 3 }} value={visible ?? ''} variant="scrollable">
|
||||
<Tabs onChange={handleVisibleChange} sx={{ px: 3 }} value={spVisible ?? ''} variant="scrollable">
|
||||
{tabs.map((tab) => (
|
||||
<Tab
|
||||
icon={<Chip label={tab.count} size="small" variant="soft" />}
|
||||
@@ -184,7 +184,7 @@ export function LessonTypesFilters({
|
||||
<Stack direction="row" spacing={2} sx={{ alignItems: 'center', flexWrap: 'wrap', px: 3, py: 2 }}>
|
||||
<Stack direction="row" spacing={2} sx={{ alignItems: 'center', flex: '1 1 auto', flexWrap: 'wrap' }}>
|
||||
<FilterButton
|
||||
displayValue={name}
|
||||
displayValue={spName}
|
||||
label={t('Name')}
|
||||
onFilterApply={(value) => {
|
||||
handleNameChange(value as string);
|
||||
@@ -193,11 +193,11 @@ export function LessonTypesFilters({
|
||||
handleNameChange();
|
||||
}}
|
||||
popover={<NameFilterPopover />}
|
||||
value={name}
|
||||
value={spName}
|
||||
/>
|
||||
|
||||
<FilterButton
|
||||
displayValue={type}
|
||||
displayValue={spType}
|
||||
label={t('Type')}
|
||||
onFilterApply={(value) => {
|
||||
handleTypeChange(value as string);
|
||||
@@ -206,7 +206,7 @@ export function LessonTypesFilters({
|
||||
handleTypeChange();
|
||||
}}
|
||||
popover={<TypeFilterPopover />}
|
||||
value={type}
|
||||
value={spType}
|
||||
/>
|
||||
|
||||
{/*
|
||||
|
Reference in New Issue
Block a user