update,
This commit is contained in:
@@ -48,7 +48,7 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
|||||||
const [rowsPerPage, setRowsPerPage] = React.useState<number>(5);
|
const [rowsPerPage, setRowsPerPage] = React.useState<number>(5);
|
||||||
//
|
//
|
||||||
const [f, setF] = React.useState<Vocabulary[]>([]);
|
const [f, setF] = React.useState<Vocabulary[]>([]);
|
||||||
const [currentPage, setCurrentPage] = React.useState<number>(1);
|
const [currentPage, setCurrentPage] = React.useState<number>(0);
|
||||||
//
|
//
|
||||||
const [recordCount, setRecordCount] = React.useState<number>(0);
|
const [recordCount, setRecordCount] = React.useState<number>(0);
|
||||||
const [listOption, setListOption] = React.useState({});
|
const [listOption, setListOption] = React.useState({});
|
||||||
@@ -57,12 +57,14 @@ export default function Page({ searchParams }: PageProps): React.JSX.Element {
|
|||||||
//
|
//
|
||||||
const reloadRows = async (): Promise<void> => {
|
const reloadRows = async (): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const models: ListResult<RecordModel> = await pb.collection(COL_VOCABULARIES).getList(1, 5, {
|
const models: ListResult<RecordModel> = await pb
|
||||||
expand: 'cat_id',
|
.collection(COL_VOCABULARIES)
|
||||||
});
|
.getList(currentPage + 1, rowsPerPage, {
|
||||||
|
...listOption,
|
||||||
|
expand: 'cat_id',
|
||||||
|
});
|
||||||
|
|
||||||
const { items, totalItems } = models;
|
const { items, totalItems } = models;
|
||||||
|
|
||||||
const tempVocabularies: Vocabulary[] = items.map((v) => {
|
const tempVocabularies: Vocabulary[] = items.map((v) => {
|
||||||
return { ...defaultVocabulary, ...v };
|
return { ...defaultVocabulary, ...v };
|
||||||
});
|
});
|
||||||
|
@@ -27,16 +27,17 @@ export interface Vocabulary {
|
|||||||
|
|
||||||
// RULES: for use with vocabulary-create-form.tsx
|
// RULES: for use with vocabulary-create-form.tsx
|
||||||
// when you update, please take a look into `vocabulary-create-form.tsx`
|
// when you update, please take a look into `vocabulary-create-form.tsx`
|
||||||
export interface CreateForm {
|
export interface CreateFormProps {
|
||||||
image?: string;
|
image: File[] | null;
|
||||||
sound?: string;
|
sound: string;
|
||||||
word?: string;
|
word: string;
|
||||||
word_c?: string;
|
word_c: string;
|
||||||
sample_e?: string;
|
sample_e: string;
|
||||||
sample_c?: string;
|
sample_c: string;
|
||||||
cat_id?: string;
|
cat_id: string;
|
||||||
category?: string;
|
category: string;
|
||||||
lesson_type_id?: string;
|
lesson_type_id: string;
|
||||||
|
visible: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RULES: for use with vocabulary-edit-form.tsx
|
// RULES: for use with vocabulary-edit-form.tsx
|
||||||
@@ -51,6 +52,7 @@ export interface EditFormProps {
|
|||||||
cat_id: string;
|
cat_id: string;
|
||||||
category: string;
|
category: string;
|
||||||
lesson_type_id: string;
|
lesson_type_id: string;
|
||||||
|
visible: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// RULES:
|
// RULES:
|
||||||
|
@@ -37,7 +37,7 @@ import { toast } from '@/components/core/toaster';
|
|||||||
import FormLoading from '@/components/loading';
|
import FormLoading from '@/components/loading';
|
||||||
|
|
||||||
import ErrorDisplay from '../error';
|
import ErrorDisplay from '../error';
|
||||||
import type { EditFormProps } from './type';
|
import type { CreateFormProps, EditFormProps } from './type';
|
||||||
import { listLessonCategories } from '@/db/LessonCategories/listLessonCategories';
|
import { listLessonCategories } from '@/db/LessonCategories/listLessonCategories';
|
||||||
import isDevelopment from '@/lib/check-is-development';
|
import isDevelopment from '@/lib/check-is-development';
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ export function VocabularyCreateForm(): React.JSX.Element {
|
|||||||
async (values: Values): Promise<void> => {
|
async (values: Values): Promise<void> => {
|
||||||
setIsCreating(true);
|
setIsCreating(true);
|
||||||
|
|
||||||
const tempUpdate: EditFormProps = {
|
const tempUpdate: CreateFormProps = {
|
||||||
image: values.avatar ? [await base64ToFile(values.avatar)] : null,
|
image: values.avatar ? [await base64ToFile(values.avatar)] : null,
|
||||||
sound: '',
|
sound: '',
|
||||||
word: values.word,
|
word: values.word,
|
||||||
@@ -104,13 +104,14 @@ export function VocabularyCreateForm(): React.JSX.Element {
|
|||||||
cat_id: values.cat_id,
|
cat_id: values.cat_id,
|
||||||
category: '',
|
category: '',
|
||||||
lesson_type_id: '',
|
lesson_type_id: '',
|
||||||
|
visible: values.visible,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = await pb.collection(COL_VOCABULARIES).create(tempUpdate);
|
const result = await pb.collection(COL_VOCABULARIES).create(tempUpdate);
|
||||||
logger.debug(result);
|
logger.debug(result);
|
||||||
toast.success(t('create.success'));
|
toast.success(t('create.success'));
|
||||||
// router.push(paths.dashboard.lesson_categories.details('1'));
|
router.push(paths.dashboard.vocabularies.list);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err);
|
logger.error(err);
|
||||||
toast.error(t('create.failed'));
|
toast.error(t('create.failed'));
|
||||||
|
@@ -101,6 +101,7 @@ export function VocabularyEditForm(): React.JSX.Element {
|
|||||||
cat_id: values.cat_id,
|
cat_id: values.cat_id,
|
||||||
category: '',
|
category: '',
|
||||||
lesson_type_id: '',
|
lesson_type_id: '',
|
||||||
|
visible: values.visible,
|
||||||
};
|
};
|
||||||
//
|
//
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user