init project portal web
This commit is contained in:
12
lib/helper/option/index.ts
Normal file
12
lib/helper/option/index.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { OptionProps } from "../type"
|
||||
|
||||
export const toOptionProps = (data: any): OptionProps[] => {
|
||||
if(!data) return []
|
||||
|
||||
return data.data.map((item: any) => {
|
||||
return {
|
||||
value: item.id,
|
||||
name: item.name
|
||||
}
|
||||
})
|
||||
}
|
||||
49
lib/helper/pagination/index.ts
Normal file
49
lib/helper/pagination/index.ts
Normal file
@ -0,0 +1,49 @@
|
||||
interface Props<T> {
|
||||
currentPage: number
|
||||
totalPages: number
|
||||
pageSize: number
|
||||
totalElements: number;
|
||||
content: T
|
||||
}
|
||||
|
||||
export default class PaginationModel<T> {
|
||||
private currentPage: number;
|
||||
private totalPages: number;
|
||||
private pageSize: number;
|
||||
private totalElements: number;
|
||||
private content: T;
|
||||
|
||||
constructor({
|
||||
currentPage,
|
||||
totalPages,
|
||||
pageSize,
|
||||
totalElements,
|
||||
content,
|
||||
}: Props<T>) {
|
||||
this.currentPage = currentPage
|
||||
this.totalPages = totalPages
|
||||
this.pageSize = pageSize
|
||||
this.totalElements = totalElements
|
||||
this.content = content
|
||||
}
|
||||
|
||||
getCurrentPage = () => this.currentPage
|
||||
|
||||
getTotalPages = () => this.totalPages
|
||||
|
||||
getPageSize = () => this.pageSize
|
||||
|
||||
getTotalElements = () => this.totalElements
|
||||
|
||||
getContent = () => this.content
|
||||
|
||||
static initialValue = () => {
|
||||
return new PaginationModel<any>({
|
||||
currentPage: 0,
|
||||
totalPages: 0,
|
||||
pageSize: 0,
|
||||
totalElements: 0,
|
||||
content: [],
|
||||
})
|
||||
};
|
||||
}
|
||||
38
lib/helper/query-data/index.ts
Normal file
38
lib/helper/query-data/index.ts
Normal file
@ -0,0 +1,38 @@
|
||||
interface Props<Tdata, Textra> {
|
||||
isLoading: boolean;
|
||||
isError: boolean;
|
||||
error: any;
|
||||
data: Tdata;
|
||||
extra: Textra;
|
||||
}
|
||||
|
||||
export default class CommonData<Tdata, Textra> {
|
||||
private isLoading: boolean;
|
||||
private isError: boolean;
|
||||
private error: any;
|
||||
private data: Tdata;
|
||||
private extra: Textra
|
||||
|
||||
constructor({ isLoading, isError, error, data, extra }: Props<Tdata, Textra>) {
|
||||
this.isLoading = isLoading;
|
||||
this.isError = isError;
|
||||
this.error = error;
|
||||
this.data = data;
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
getIsLoading(): boolean {
|
||||
return this.isLoading;
|
||||
}
|
||||
getIsError(): boolean {
|
||||
return this.isError;
|
||||
}
|
||||
getError(): any {
|
||||
return this.error;
|
||||
}
|
||||
getData(): Tdata {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
getExtra = () => this.extra;
|
||||
}
|
||||
10
lib/helper/type/index.ts
Normal file
10
lib/helper/type/index.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export type FormStore<T extends object> = T & {
|
||||
setField: <K extends keyof T>(key: K, value: T[K]) => void
|
||||
setFields: (fields: Partial<T>) => void
|
||||
resetForm: () => void
|
||||
}
|
||||
|
||||
export type OptionProps = {
|
||||
value: string
|
||||
name: string
|
||||
}
|
||||
Reference in New Issue
Block a user