init project portal web

This commit is contained in:
Sweli Giri
2025-04-15 13:56:54 +07:00
parent 9a25243035
commit 8b15dcebf8
122 changed files with 13965 additions and 1 deletions

View File

@ -0,0 +1,65 @@
import PricePlanModel from "../model/price-plan-model"
import PaginationModel from "@/lib/helper/pagination"
import { usePricePlanQuery, usePricePlanTypesQuery, useServiceTypesQuery } from "../queries"
import { useCreatePricePlanMutation, useDeletePricePlanMutation } from "../mutations"
type UsePricePlanReturn = {
isLoading: boolean
isError: boolean
error: unknown
data: PaginationModel<PricePlanModel[]>
ppTypes: Array<{[key: string]: string}>
serviceTypes: Array<{[key: string]: string}>
extra: {
deletePricePlan: (id: string) => void
createPricePlan: (payload: any) => void
isDeleting: boolean
isCreating: boolean
}
}
export const usePricePlan = (
page: number,
size: number,
type: string,
onCreateSuccess: () => void
): UsePricePlanReturn => {
// Queries
const priceplanQuery = usePricePlanQuery(page, size, type)
const ppTypesQuery = usePricePlanTypesQuery()
const servTypesQuery = useServiceTypesQuery()
// Mutations
const deleteMutation = useDeletePricePlanMutation()
const createMutation = useCreatePricePlanMutation(onCreateSuccess)
// Data
const dataJson: any = priceplanQuery.data
const ppTypes: any = ppTypesQuery.data
const serviceTypes: any = servTypesQuery.data
let models: PricePlanModel[] = []
if (dataJson) {
models = PricePlanModel.fromJSON(dataJson)
}
return {
isLoading: priceplanQuery.isLoading,
isError: priceplanQuery.isError,
error: priceplanQuery.error,
data: priceplanQuery.data ? new PaginationModel({
currentPage: dataJson.data.number,
totalPages: dataJson.data.totalPages,
pageSize: dataJson.data.size,
totalElements: dataJson.data.totalElements,
content: models,
}) : PaginationModel.initialValue(),
ppTypes: ppTypes ? ppTypes.data : [],
serviceTypes: serviceTypes ? serviceTypes?.data.map((item: any) => {{
return {id: item.id, servTypeName: item.servTypeName}
}}).slice(0, 100) : [],
extra: {
deletePricePlan: deleteMutation.mutate,
isDeleting: deleteMutation.isPending,
createPricePlan: createMutation.mutate,
isCreating: createMutation.isPending
}
}
}