Commit ddf84539 authored by Lê Bảo Hồng Đức's avatar Lê Bảo Hồng Đức

add api

parent d5379f01
......@@ -123,6 +123,8 @@ const orvalConfig = async () => {
'News',
'Category',
'NewsPageConfig',
'Video',
'NewsletterSubscription',
],
},
},
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import {
......@@ -31,140 +31,138 @@ import type {
import type {
CategoryMutate,
DeleteApiV10CategoryId200,
GetApiV10CategoryId200,
GetApiV10CategoryParams,
PostApiV10Category200,
PutApiV10CategoryId200,
DeleteCategoryId200,
GetCategoryId200,
GetCategoryParams,
PostCategory200,
PutCategoryId200,
ResponseGetAllData
} from '../models';
import { useCustomClient } from '../mutator/custom-client';
import type { ErrorType , BodyType } from '../mutator/custom-client';
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
/**
* Retrieve a single category record by its ID
* @summary Get category by ID
*/
export type getApiV10CategoryIdResponse200 = {
data: GetApiV10CategoryId200
export type getCategoryIdResponse200 = {
data: GetCategoryId200
status: 200
}
export type getApiV10CategoryIdResponse404 = {
export type getCategoryIdResponse404 = {
data: void
status: 404
}
export type getApiV10CategoryIdResponseSuccess = (getApiV10CategoryIdResponse200) & {
export type getCategoryIdResponseSuccess = (getCategoryIdResponse200) & {
headers: Headers;
};
export type getApiV10CategoryIdResponseError = (getApiV10CategoryIdResponse404) & {
export type getCategoryIdResponseError = (getCategoryIdResponse404) & {
headers: Headers;
};
export type getApiV10CategoryIdResponse = (getApiV10CategoryIdResponseSuccess | getApiV10CategoryIdResponseError)
export type getCategoryIdResponse = (getCategoryIdResponseSuccess | getCategoryIdResponseError)
export const getGetApiV10CategoryIdUrl = (id: string,) => {
export const getGetCategoryIdUrl = (id: string,) => {
return `/api/v1.0/category/${id}`
return `/category/${id}`
}
export const getApiV10CategoryId = async (id: string, options?: RequestInit): Promise<getApiV10CategoryIdResponse> => {
export const getCategoryId = async (id: string, options?: RequestInit): Promise<getCategoryIdResponse> => {
const res = await fetch(getGetApiV10CategoryIdUrl(id),
return useCustomClient<getCategoryIdResponse>(getGetCategoryIdUrl(id),
{
...options,
method: 'GET'
}
)
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: getApiV10CategoryIdResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as getApiV10CategoryIdResponse
}
);}
export const getGetApiV10CategoryIdInfiniteQueryKey = (id?: string,) => {
export const getGetCategoryIdInfiniteQueryKey = (id?: string,) => {
return [
'infinite', `/api/v1.0/category/${id}`
'infinite', `/category/${id}`
] as const;
}
export const getGetApiV10CategoryIdQueryKey = (id?: string,) => {
export const getGetCategoryIdQueryKey = (id?: string,) => {
return [
`/api/v1.0/category/${id}`
`/category/${id}`
] as const;
}
export const getGetApiV10CategoryIdInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getApiV10CategoryId>>>, TError = void>(id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData>>, fetch?: RequestInit}
export const getGetCategoryIdInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getCategoryId>>>, TError = ErrorType<void>>(id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, fetch: fetchOptions} = options ?? {};
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetApiV10CategoryIdInfiniteQueryKey(id);
const queryKey = queryOptions?.queryKey ?? getGetCategoryIdInfiniteQueryKey(id);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getApiV10CategoryId>>> = ({ signal }) => getApiV10CategoryId(id, { signal, ...fetchOptions });
const queryFn: QueryFunction<Awaited<ReturnType<typeof getCategoryId>>> = ({ signal }) => getCategoryId(id, { signal, ...requestOptions });
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetApiV10CategoryIdInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getApiV10CategoryId>>>
export type GetApiV10CategoryIdInfiniteQueryError = void
export type GetCategoryIdInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getCategoryId>>>
export type GetCategoryIdInfiniteQueryError = ErrorType<void>
export function useGetApiV10CategoryIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10CategoryId>>>, TError = void>(
id: string, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData>> & Pick<
export function useGetCategoryIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getCategoryId>>>, TError = ErrorType<void>>(
id: string, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10CategoryId>>,
Awaited<ReturnType<typeof getCategoryId>>,
TError,
Awaited<ReturnType<typeof getApiV10CategoryId>>
Awaited<ReturnType<typeof getCategoryId>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10CategoryIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10CategoryId>>>, TError = void>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData>> & Pick<
export function useGetCategoryIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getCategoryId>>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10CategoryId>>,
Awaited<ReturnType<typeof getCategoryId>>,
TError,
Awaited<ReturnType<typeof getApiV10CategoryId>>
Awaited<ReturnType<typeof getCategoryId>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10CategoryIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10CategoryId>>>, TError = void>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData>>, fetch?: RequestInit}
export function useGetCategoryIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getCategoryId>>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get category by ID
*/
export function useGetApiV10CategoryIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10CategoryId>>>, TError = void>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData>>, fetch?: RequestInit}
export function useGetCategoryIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getCategoryId>>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetApiV10CategoryIdInfiniteQueryOptions(id,options)
const queryOptions = getGetCategoryIdInfiniteQueryOptions(id,options)
const query = useInfiniteQuery(queryOptions, queryClient) as UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
......@@ -176,12 +174,12 @@ export function useGetApiV10CategoryIdInfinite<TData = InfiniteData<Awaited<Retu
/**
* @summary Get category by ID
*/
export const prefetchGetApiV10CategoryIdInfiniteQuery = async <TData = Awaited<ReturnType<typeof getApiV10CategoryId>>, TError = void>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData>>, fetch?: RequestInit}
export const prefetchGetCategoryIdInfiniteQuery = async <TData = Awaited<ReturnType<typeof getCategoryId>>, TError = ErrorType<void>>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetApiV10CategoryIdInfiniteQueryOptions(id,options)
const queryOptions = getGetCategoryIdInfiniteQueryOptions(id,options)
await queryClient.prefetchInfiniteQuery(queryOptions);
......@@ -190,62 +188,62 @@ export const prefetchGetApiV10CategoryIdInfiniteQuery = async <TData = Awaited<R
export const getGetApiV10CategoryIdQueryOptions = <TData = Awaited<ReturnType<typeof getApiV10CategoryId>>, TError = void>(id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData>>, fetch?: RequestInit}
export const getGetCategoryIdQueryOptions = <TData = Awaited<ReturnType<typeof getCategoryId>>, TError = ErrorType<void>>(id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, fetch: fetchOptions} = options ?? {};
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetApiV10CategoryIdQueryKey(id);
const queryKey = queryOptions?.queryKey ?? getGetCategoryIdQueryKey(id);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getApiV10CategoryId>>> = ({ signal }) => getApiV10CategoryId(id, { signal, ...fetchOptions });
const queryFn: QueryFunction<Awaited<ReturnType<typeof getCategoryId>>> = ({ signal }) => getCategoryId(id, { signal, ...requestOptions });
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetApiV10CategoryIdQueryResult = NonNullable<Awaited<ReturnType<typeof getApiV10CategoryId>>>
export type GetApiV10CategoryIdQueryError = void
export type GetCategoryIdQueryResult = NonNullable<Awaited<ReturnType<typeof getCategoryId>>>
export type GetCategoryIdQueryError = ErrorType<void>
export function useGetApiV10CategoryId<TData = Awaited<ReturnType<typeof getApiV10CategoryId>>, TError = void>(
id: string, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData>> & Pick<
export function useGetCategoryId<TData = Awaited<ReturnType<typeof getCategoryId>>, TError = ErrorType<void>>(
id: string, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10CategoryId>>,
Awaited<ReturnType<typeof getCategoryId>>,
TError,
Awaited<ReturnType<typeof getApiV10CategoryId>>
Awaited<ReturnType<typeof getCategoryId>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10CategoryId<TData = Awaited<ReturnType<typeof getApiV10CategoryId>>, TError = void>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData>> & Pick<
export function useGetCategoryId<TData = Awaited<ReturnType<typeof getCategoryId>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10CategoryId>>,
Awaited<ReturnType<typeof getCategoryId>>,
TError,
Awaited<ReturnType<typeof getApiV10CategoryId>>
Awaited<ReturnType<typeof getCategoryId>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10CategoryId<TData = Awaited<ReturnType<typeof getApiV10CategoryId>>, TError = void>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData>>, fetch?: RequestInit}
export function useGetCategoryId<TData = Awaited<ReturnType<typeof getCategoryId>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get category by ID
*/
export function useGetApiV10CategoryId<TData = Awaited<ReturnType<typeof getApiV10CategoryId>>, TError = void>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData>>, fetch?: RequestInit}
export function useGetCategoryId<TData = Awaited<ReturnType<typeof getCategoryId>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetApiV10CategoryIdQueryOptions(id,options)
const queryOptions = getGetCategoryIdQueryOptions(id,options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
......@@ -257,12 +255,12 @@ export function useGetApiV10CategoryId<TData = Awaited<ReturnType<typeof getApiV
/**
* @summary Get category by ID
*/
export const prefetchGetApiV10CategoryIdQuery = async <TData = Awaited<ReturnType<typeof getApiV10CategoryId>>, TError = void>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10CategoryId>>, TError, TData>>, fetch?: RequestInit}
export const prefetchGetCategoryIdQuery = async <TData = Awaited<ReturnType<typeof getCategoryId>>, TError = ErrorType<void>>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getCategoryId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetApiV10CategoryIdQueryOptions(id,options)
const queryOptions = getGetCategoryIdQueryOptions(id,options)
await queryClient.prefetchQuery(queryOptions);
......@@ -275,37 +273,37 @@ export const prefetchGetApiV10CategoryIdQuery = async <TData = Awaited<ReturnTyp
* Update a single category record by its ID
* @summary Update category by ID
*/
export type putApiV10CategoryIdResponse200 = {
data: PutApiV10CategoryId200
export type putCategoryIdResponse200 = {
data: PutCategoryId200
status: 200
}
export type putApiV10CategoryIdResponse404 = {
export type putCategoryIdResponse404 = {
data: void
status: 404
}
export type putApiV10CategoryIdResponseSuccess = (putApiV10CategoryIdResponse200) & {
export type putCategoryIdResponseSuccess = (putCategoryIdResponse200) & {
headers: Headers;
};
export type putApiV10CategoryIdResponseError = (putApiV10CategoryIdResponse404) & {
export type putCategoryIdResponseError = (putCategoryIdResponse404) & {
headers: Headers;
};
export type putApiV10CategoryIdResponse = (putApiV10CategoryIdResponseSuccess | putApiV10CategoryIdResponseError)
export type putCategoryIdResponse = (putCategoryIdResponseSuccess | putCategoryIdResponseError)
export const getPutApiV10CategoryIdUrl = (id: string,) => {
export const getPutCategoryIdUrl = (id: string,) => {
return `/api/v1.0/category/${id}`
return `/category/${id}`
}
export const putApiV10CategoryId = async (id: string,
categoryMutate: CategoryMutate, options?: RequestInit): Promise<putApiV10CategoryIdResponse> => {
export const putCategoryId = async (id: string,
categoryMutate: CategoryMutate, options?: RequestInit): Promise<putCategoryIdResponse> => {
const res = await fetch(getPutApiV10CategoryIdUrl(id),
return useCustomClient<putCategoryIdResponse>(getPutCategoryIdUrl(id),
{
...options,
method: 'PUT',
......@@ -313,35 +311,29 @@ export const putApiV10CategoryId = async (id: string,
body: JSON.stringify(
categoryMutate,)
}
)
);}
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: putApiV10CategoryIdResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as putApiV10CategoryIdResponse
}
export const getPutCategoryIdMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putCategoryId>>, TError,{id: string;data: BodyType<CategoryMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof putCategoryId>>, TError,{id: string;data: BodyType<CategoryMutate>}, TContext> => {
export const getPutApiV10CategoryIdMutationOptions = <TError = void,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putApiV10CategoryId>>, TError,{id: string;data: CategoryMutate}, TContext>, fetch?: RequestInit}
): UseMutationOptions<Awaited<ReturnType<typeof putApiV10CategoryId>>, TError,{id: string;data: CategoryMutate}, TContext> => {
const mutationKey = ['putApiV10CategoryId'];
const {mutation: mutationOptions, fetch: fetchOptions} = options ?
const mutationKey = ['putCategoryId'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, fetch: undefined};
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof putApiV10CategoryId>>, {id: string;data: CategoryMutate}> = (props) => {
const mutationFn: MutationFunction<Awaited<ReturnType<typeof putCategoryId>>, {id: string;data: BodyType<CategoryMutate>}> = (props) => {
const {id,data} = props ?? {};
return putApiV10CategoryId(id,data,fetchOptions)
return putCategoryId(id,data,requestOptions)
}
......@@ -349,23 +341,23 @@ const {mutation: mutationOptions, fetch: fetchOptions} = options ?
return { mutationFn, ...mutationOptions }}
export type PutApiV10CategoryIdMutationResult = NonNullable<Awaited<ReturnType<typeof putApiV10CategoryId>>>
export type PutApiV10CategoryIdMutationBody = CategoryMutate
export type PutApiV10CategoryIdMutationError = void
export type PutCategoryIdMutationResult = NonNullable<Awaited<ReturnType<typeof putCategoryId>>>
export type PutCategoryIdMutationBody = BodyType<CategoryMutate>
export type PutCategoryIdMutationError = ErrorType<void>
/**
* @summary Update category by ID
*/
export const usePutApiV10CategoryId = <TError = void,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putApiV10CategoryId>>, TError,{id: string;data: CategoryMutate}, TContext>, fetch?: RequestInit}
export const usePutCategoryId = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putCategoryId>>, TError,{id: string;data: BodyType<CategoryMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof putApiV10CategoryId>>,
Awaited<ReturnType<typeof putCategoryId>>,
TError,
{id: string;data: CategoryMutate},
{id: string;data: BodyType<CategoryMutate>},
TContext
> => {
const mutationOptions = getPutApiV10CategoryIdMutationOptions(options);
const mutationOptions = getPutCategoryIdMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
......@@ -373,71 +365,65 @@ export const usePutApiV10CategoryId = <TError = void,
* Delete a single category record by its ID
* @summary Delete category by ID
*/
export type deleteApiV10CategoryIdResponse200 = {
data: DeleteApiV10CategoryId200
export type deleteCategoryIdResponse200 = {
data: DeleteCategoryId200
status: 200
}
export type deleteApiV10CategoryIdResponse404 = {
export type deleteCategoryIdResponse404 = {
data: void
status: 404
}
export type deleteApiV10CategoryIdResponseSuccess = (deleteApiV10CategoryIdResponse200) & {
export type deleteCategoryIdResponseSuccess = (deleteCategoryIdResponse200) & {
headers: Headers;
};
export type deleteApiV10CategoryIdResponseError = (deleteApiV10CategoryIdResponse404) & {
export type deleteCategoryIdResponseError = (deleteCategoryIdResponse404) & {
headers: Headers;
};
export type deleteApiV10CategoryIdResponse = (deleteApiV10CategoryIdResponseSuccess | deleteApiV10CategoryIdResponseError)
export type deleteCategoryIdResponse = (deleteCategoryIdResponseSuccess | deleteCategoryIdResponseError)
export const getDeleteApiV10CategoryIdUrl = (id: string,) => {
export const getDeleteCategoryIdUrl = (id: string,) => {
return `/api/v1.0/category/${id}`
return `/category/${id}`
}
export const deleteApiV10CategoryId = async (id: string, options?: RequestInit): Promise<deleteApiV10CategoryIdResponse> => {
export const deleteCategoryId = async (id: string, options?: RequestInit): Promise<deleteCategoryIdResponse> => {
const res = await fetch(getDeleteApiV10CategoryIdUrl(id),
return useCustomClient<deleteCategoryIdResponse>(getDeleteCategoryIdUrl(id),
{
...options,
method: 'DELETE'
}
)
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: deleteApiV10CategoryIdResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as deleteApiV10CategoryIdResponse
}
);}
export const getDeleteApiV10CategoryIdMutationOptions = <TError = void,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteApiV10CategoryId>>, TError,{id: string}, TContext>, fetch?: RequestInit}
): UseMutationOptions<Awaited<ReturnType<typeof deleteApiV10CategoryId>>, TError,{id: string}, TContext> => {
export const getDeleteCategoryIdMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteCategoryId>>, TError,{id: string}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof deleteCategoryId>>, TError,{id: string}, TContext> => {
const mutationKey = ['deleteApiV10CategoryId'];
const {mutation: mutationOptions, fetch: fetchOptions} = options ?
const mutationKey = ['deleteCategoryId'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, fetch: undefined};
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteApiV10CategoryId>>, {id: string}> = (props) => {
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteCategoryId>>, {id: string}> = (props) => {
const {id} = props ?? {};
return deleteApiV10CategoryId(id,fetchOptions)
return deleteCategoryId(id,requestOptions)
}
......@@ -445,23 +431,23 @@ const {mutation: mutationOptions, fetch: fetchOptions} = options ?
return { mutationFn, ...mutationOptions }}
export type DeleteApiV10CategoryIdMutationResult = NonNullable<Awaited<ReturnType<typeof deleteApiV10CategoryId>>>
export type DeleteCategoryIdMutationResult = NonNullable<Awaited<ReturnType<typeof deleteCategoryId>>>
export type DeleteApiV10CategoryIdMutationError = void
export type DeleteCategoryIdMutationError = ErrorType<void>
/**
* @summary Delete category by ID
*/
export const useDeleteApiV10CategoryId = <TError = void,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteApiV10CategoryId>>, TError,{id: string}, TContext>, fetch?: RequestInit}
export const useDeleteCategoryId = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteCategoryId>>, TError,{id: string}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof deleteApiV10CategoryId>>,
Awaited<ReturnType<typeof deleteCategoryId>>,
TError,
{id: string},
TContext
> => {
const mutationOptions = getDeleteApiV10CategoryIdMutationOptions(options);
const mutationOptions = getDeleteCategoryIdMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
......@@ -469,19 +455,19 @@ export const useDeleteApiV10CategoryId = <TError = void,
* Retrieve a list of category with pagination, filtering and sorting
* @summary Get all category
*/
export type getApiV10CategoryResponse200 = {
export type getCategoryResponse200 = {
data: ResponseGetAllData
status: 200
}
export type getApiV10CategoryResponseSuccess = (getApiV10CategoryResponse200) & {
export type getCategoryResponseSuccess = (getCategoryResponse200) & {
headers: Headers;
};
;
export type getApiV10CategoryResponse = (getApiV10CategoryResponseSuccess)
export type getCategoryResponse = (getCategoryResponseSuccess)
export const getGetApiV10CategoryUrl = (params?: GetApiV10CategoryParams,) => {
export const getGetCategoryUrl = (params?: GetCategoryParams,) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
......@@ -493,99 +479,93 @@ export const getGetApiV10CategoryUrl = (params?: GetApiV10CategoryParams,) => {
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0 ? `/api/v1.0/category?${stringifiedParams}` : `/api/v1.0/category`
return stringifiedParams.length > 0 ? `/category?${stringifiedParams}` : `/category`
}
export const getApiV10Category = async (params?: GetApiV10CategoryParams, options?: RequestInit): Promise<getApiV10CategoryResponse> => {
export const getCategory = async (params?: GetCategoryParams, options?: RequestInit): Promise<getCategoryResponse> => {
const res = await fetch(getGetApiV10CategoryUrl(params),
return useCustomClient<getCategoryResponse>(getGetCategoryUrl(params),
{
...options,
method: 'GET'
}
)
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: getApiV10CategoryResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as getApiV10CategoryResponse
}
);}
export const getGetApiV10CategoryInfiniteQueryKey = (params?: GetApiV10CategoryParams,) => {
export const getGetCategoryInfiniteQueryKey = (params?: GetCategoryParams,) => {
return [
'infinite', `/api/v1.0/category`, ...(params ? [params]: [])
'infinite', `/category`, ...(params ? [params]: [])
] as const;
}
export const getGetApiV10CategoryQueryKey = (params?: GetApiV10CategoryParams,) => {
export const getGetCategoryQueryKey = (params?: GetCategoryParams,) => {
return [
`/api/v1.0/category`, ...(params ? [params]: [])
`/category`, ...(params ? [params]: [])
] as const;
}
export const getGetApiV10CategoryInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getApiV10Category>>>, TError = unknown>(params?: GetApiV10CategoryParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData>>, fetch?: RequestInit}
export const getGetCategoryInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getCategory>>>, TError = ErrorType<unknown>>(params?: GetCategoryParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, fetch: fetchOptions} = options ?? {};
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetApiV10CategoryInfiniteQueryKey(params);
const queryKey = queryOptions?.queryKey ?? getGetCategoryInfiniteQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getApiV10Category>>> = ({ signal }) => getApiV10Category(params, { signal, ...fetchOptions });
const queryFn: QueryFunction<Awaited<ReturnType<typeof getCategory>>> = ({ signal }) => getCategory(params, { signal, ...requestOptions });
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetApiV10CategoryInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getApiV10Category>>>
export type GetApiV10CategoryInfiniteQueryError = unknown
export type GetCategoryInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getCategory>>>
export type GetCategoryInfiniteQueryError = ErrorType<unknown>
export function useGetApiV10CategoryInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10Category>>>, TError = unknown>(
params: undefined | GetApiV10CategoryParams, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData>> & Pick<
export function useGetCategoryInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getCategory>>>, TError = ErrorType<unknown>>(
params: undefined | GetCategoryParams, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10Category>>,
Awaited<ReturnType<typeof getCategory>>,
TError,
Awaited<ReturnType<typeof getApiV10Category>>
Awaited<ReturnType<typeof getCategory>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10CategoryInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10Category>>>, TError = unknown>(
params?: GetApiV10CategoryParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData>> & Pick<
export function useGetCategoryInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getCategory>>>, TError = ErrorType<unknown>>(
params?: GetCategoryParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10Category>>,
Awaited<ReturnType<typeof getCategory>>,
TError,
Awaited<ReturnType<typeof getApiV10Category>>
Awaited<ReturnType<typeof getCategory>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10CategoryInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10Category>>>, TError = unknown>(
params?: GetApiV10CategoryParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData>>, fetch?: RequestInit}
export function useGetCategoryInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getCategory>>>, TError = ErrorType<unknown>>(
params?: GetCategoryParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get all category
*/
export function useGetApiV10CategoryInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10Category>>>, TError = unknown>(
params?: GetApiV10CategoryParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData>>, fetch?: RequestInit}
export function useGetCategoryInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getCategory>>>, TError = ErrorType<unknown>>(
params?: GetCategoryParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetApiV10CategoryInfiniteQueryOptions(params,options)
const queryOptions = getGetCategoryInfiniteQueryOptions(params,options)
const query = useInfiniteQuery(queryOptions, queryClient) as UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
......@@ -597,12 +577,12 @@ export function useGetApiV10CategoryInfinite<TData = InfiniteData<Awaited<Return
/**
* @summary Get all category
*/
export const prefetchGetApiV10CategoryInfiniteQuery = async <TData = Awaited<ReturnType<typeof getApiV10Category>>, TError = unknown>(
queryClient: QueryClient, params?: GetApiV10CategoryParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData>>, fetch?: RequestInit}
export const prefetchGetCategoryInfiniteQuery = async <TData = Awaited<ReturnType<typeof getCategory>>, TError = ErrorType<unknown>>(
queryClient: QueryClient, params?: GetCategoryParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetApiV10CategoryInfiniteQueryOptions(params,options)
const queryOptions = getGetCategoryInfiniteQueryOptions(params,options)
await queryClient.prefetchInfiniteQuery(queryOptions);
......@@ -611,62 +591,62 @@ export const prefetchGetApiV10CategoryInfiniteQuery = async <TData = Awaited<Ret
export const getGetApiV10CategoryQueryOptions = <TData = Awaited<ReturnType<typeof getApiV10Category>>, TError = unknown>(params?: GetApiV10CategoryParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData>>, fetch?: RequestInit}
export const getGetCategoryQueryOptions = <TData = Awaited<ReturnType<typeof getCategory>>, TError = ErrorType<unknown>>(params?: GetCategoryParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, fetch: fetchOptions} = options ?? {};
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetApiV10CategoryQueryKey(params);
const queryKey = queryOptions?.queryKey ?? getGetCategoryQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getApiV10Category>>> = ({ signal }) => getApiV10Category(params, { signal, ...fetchOptions });
const queryFn: QueryFunction<Awaited<ReturnType<typeof getCategory>>> = ({ signal }) => getCategory(params, { signal, ...requestOptions });
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetApiV10CategoryQueryResult = NonNullable<Awaited<ReturnType<typeof getApiV10Category>>>
export type GetApiV10CategoryQueryError = unknown
export type GetCategoryQueryResult = NonNullable<Awaited<ReturnType<typeof getCategory>>>
export type GetCategoryQueryError = ErrorType<unknown>
export function useGetApiV10Category<TData = Awaited<ReturnType<typeof getApiV10Category>>, TError = unknown>(
params: undefined | GetApiV10CategoryParams, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData>> & Pick<
export function useGetCategory<TData = Awaited<ReturnType<typeof getCategory>>, TError = ErrorType<unknown>>(
params: undefined | GetCategoryParams, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10Category>>,
Awaited<ReturnType<typeof getCategory>>,
TError,
Awaited<ReturnType<typeof getApiV10Category>>
Awaited<ReturnType<typeof getCategory>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10Category<TData = Awaited<ReturnType<typeof getApiV10Category>>, TError = unknown>(
params?: GetApiV10CategoryParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData>> & Pick<
export function useGetCategory<TData = Awaited<ReturnType<typeof getCategory>>, TError = ErrorType<unknown>>(
params?: GetCategoryParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10Category>>,
Awaited<ReturnType<typeof getCategory>>,
TError,
Awaited<ReturnType<typeof getApiV10Category>>
Awaited<ReturnType<typeof getCategory>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10Category<TData = Awaited<ReturnType<typeof getApiV10Category>>, TError = unknown>(
params?: GetApiV10CategoryParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData>>, fetch?: RequestInit}
export function useGetCategory<TData = Awaited<ReturnType<typeof getCategory>>, TError = ErrorType<unknown>>(
params?: GetCategoryParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get all category
*/
export function useGetApiV10Category<TData = Awaited<ReturnType<typeof getApiV10Category>>, TError = unknown>(
params?: GetApiV10CategoryParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData>>, fetch?: RequestInit}
export function useGetCategory<TData = Awaited<ReturnType<typeof getCategory>>, TError = ErrorType<unknown>>(
params?: GetCategoryParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetApiV10CategoryQueryOptions(params,options)
const queryOptions = getGetCategoryQueryOptions(params,options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
......@@ -678,12 +658,12 @@ export function useGetApiV10Category<TData = Awaited<ReturnType<typeof getApiV10
/**
* @summary Get all category
*/
export const prefetchGetApiV10CategoryQuery = async <TData = Awaited<ReturnType<typeof getApiV10Category>>, TError = unknown>(
queryClient: QueryClient, params?: GetApiV10CategoryParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10Category>>, TError, TData>>, fetch?: RequestInit}
export const prefetchGetCategoryQuery = async <TData = Awaited<ReturnType<typeof getCategory>>, TError = ErrorType<unknown>>(
queryClient: QueryClient, params?: GetCategoryParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getCategory>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetApiV10CategoryQueryOptions(params,options)
const queryOptions = getGetCategoryQueryOptions(params,options)
await queryClient.prefetchQuery(queryOptions);
......@@ -696,29 +676,29 @@ export const prefetchGetApiV10CategoryQuery = async <TData = Awaited<ReturnType<
* Create a new category record
* @summary Create a category
*/
export type postApiV10CategoryResponse200 = {
data: PostApiV10Category200
export type postCategoryResponse200 = {
data: PostCategory200
status: 200
}
export type postApiV10CategoryResponseSuccess = (postApiV10CategoryResponse200) & {
export type postCategoryResponseSuccess = (postCategoryResponse200) & {
headers: Headers;
};
;
export type postApiV10CategoryResponse = (postApiV10CategoryResponseSuccess)
export type postCategoryResponse = (postCategoryResponseSuccess)
export const getPostApiV10CategoryUrl = () => {
export const getPostCategoryUrl = () => {
return `/api/v1.0/category`
return `/category`
}
export const postApiV10Category = async (categoryMutate: CategoryMutate, options?: RequestInit): Promise<postApiV10CategoryResponse> => {
export const postCategory = async (categoryMutate: CategoryMutate, options?: RequestInit): Promise<postCategoryResponse> => {
const res = await fetch(getPostApiV10CategoryUrl(),
return useCustomClient<postCategoryResponse>(getPostCategoryUrl(),
{
...options,
method: 'POST',
......@@ -726,35 +706,29 @@ export const postApiV10Category = async (categoryMutate: CategoryMutate, options
body: JSON.stringify(
categoryMutate,)
}
)
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: postApiV10CategoryResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as postApiV10CategoryResponse
}
);}
export const getPostApiV10CategoryMutationOptions = <TError = unknown,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postApiV10Category>>, TError,{data: CategoryMutate}, TContext>, fetch?: RequestInit}
): UseMutationOptions<Awaited<ReturnType<typeof postApiV10Category>>, TError,{data: CategoryMutate}, TContext> => {
export const getPostCategoryMutationOptions = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postCategory>>, TError,{data: BodyType<CategoryMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof postCategory>>, TError,{data: BodyType<CategoryMutate>}, TContext> => {
const mutationKey = ['postApiV10Category'];
const {mutation: mutationOptions, fetch: fetchOptions} = options ?
const mutationKey = ['postCategory'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, fetch: undefined};
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof postApiV10Category>>, {data: CategoryMutate}> = (props) => {
const mutationFn: MutationFunction<Awaited<ReturnType<typeof postCategory>>, {data: BodyType<CategoryMutate>}> = (props) => {
const {data} = props ?? {};
return postApiV10Category(data,fetchOptions)
return postCategory(data,requestOptions)
}
......@@ -762,23 +736,23 @@ const {mutation: mutationOptions, fetch: fetchOptions} = options ?
return { mutationFn, ...mutationOptions }}
export type PostApiV10CategoryMutationResult = NonNullable<Awaited<ReturnType<typeof postApiV10Category>>>
export type PostApiV10CategoryMutationBody = CategoryMutate
export type PostApiV10CategoryMutationError = unknown
export type PostCategoryMutationResult = NonNullable<Awaited<ReturnType<typeof postCategory>>>
export type PostCategoryMutationBody = BodyType<CategoryMutate>
export type PostCategoryMutationError = ErrorType<unknown>
/**
* @summary Create a category
*/
export const usePostApiV10Category = <TError = unknown,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postApiV10Category>>, TError,{data: CategoryMutate}, TContext>, fetch?: RequestInit}
export const usePostCategory = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postCategory>>, TError,{data: BodyType<CategoryMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof postApiV10Category>>,
Awaited<ReturnType<typeof postCategory>>,
TError,
{data: CategoryMutate},
{data: BodyType<CategoryMutate>},
TContext
> => {
const mutationOptions = getPostApiV10CategoryMutationOptions(options);
const mutationOptions = getPostCategoryMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import {
......@@ -31,140 +31,138 @@ import type {
import type {
ContactMutate,
DeleteApiV10ContactId200,
GetApiV10ContactId200,
GetApiV10ContactParams,
PostApiV10Contact200,
PutApiV10ContactId200,
DeleteContactId200,
GetContactId200,
GetContactParams,
PostContact200,
PutContactId200,
ResponseGetAllData
} from '../models';
import { useCustomClient } from '../mutator/custom-client';
import type { ErrorType , BodyType } from '../mutator/custom-client';
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
/**
* Retrieve a single contact record by its ID
* @summary Get contact by ID
*/
export type getApiV10ContactIdResponse200 = {
data: GetApiV10ContactId200
export type getContactIdResponse200 = {
data: GetContactId200
status: 200
}
export type getApiV10ContactIdResponse404 = {
export type getContactIdResponse404 = {
data: void
status: 404
}
export type getApiV10ContactIdResponseSuccess = (getApiV10ContactIdResponse200) & {
export type getContactIdResponseSuccess = (getContactIdResponse200) & {
headers: Headers;
};
export type getApiV10ContactIdResponseError = (getApiV10ContactIdResponse404) & {
export type getContactIdResponseError = (getContactIdResponse404) & {
headers: Headers;
};
export type getApiV10ContactIdResponse = (getApiV10ContactIdResponseSuccess | getApiV10ContactIdResponseError)
export type getContactIdResponse = (getContactIdResponseSuccess | getContactIdResponseError)
export const getGetApiV10ContactIdUrl = (id: string,) => {
export const getGetContactIdUrl = (id: string,) => {
return `/api/v1.0/contact/${id}`
return `/contact/${id}`
}
export const getApiV10ContactId = async (id: string, options?: RequestInit): Promise<getApiV10ContactIdResponse> => {
export const getContactId = async (id: string, options?: RequestInit): Promise<getContactIdResponse> => {
const res = await fetch(getGetApiV10ContactIdUrl(id),
return useCustomClient<getContactIdResponse>(getGetContactIdUrl(id),
{
...options,
method: 'GET'
}
)
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: getApiV10ContactIdResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as getApiV10ContactIdResponse
}
);}
export const getGetApiV10ContactIdInfiniteQueryKey = (id?: string,) => {
export const getGetContactIdInfiniteQueryKey = (id?: string,) => {
return [
'infinite', `/api/v1.0/contact/${id}`
'infinite', `/contact/${id}`
] as const;
}
export const getGetApiV10ContactIdQueryKey = (id?: string,) => {
export const getGetContactIdQueryKey = (id?: string,) => {
return [
`/api/v1.0/contact/${id}`
`/contact/${id}`
] as const;
}
export const getGetApiV10ContactIdInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getApiV10ContactId>>>, TError = void>(id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData>>, fetch?: RequestInit}
export const getGetContactIdInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getContactId>>>, TError = ErrorType<void>>(id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, fetch: fetchOptions} = options ?? {};
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetApiV10ContactIdInfiniteQueryKey(id);
const queryKey = queryOptions?.queryKey ?? getGetContactIdInfiniteQueryKey(id);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getApiV10ContactId>>> = ({ signal }) => getApiV10ContactId(id, { signal, ...fetchOptions });
const queryFn: QueryFunction<Awaited<ReturnType<typeof getContactId>>> = ({ signal }) => getContactId(id, { signal, ...requestOptions });
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetApiV10ContactIdInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getApiV10ContactId>>>
export type GetApiV10ContactIdInfiniteQueryError = void
export type GetContactIdInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getContactId>>>
export type GetContactIdInfiniteQueryError = ErrorType<void>
export function useGetApiV10ContactIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10ContactId>>>, TError = void>(
id: string, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData>> & Pick<
export function useGetContactIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getContactId>>>, TError = ErrorType<void>>(
id: string, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10ContactId>>,
Awaited<ReturnType<typeof getContactId>>,
TError,
Awaited<ReturnType<typeof getApiV10ContactId>>
Awaited<ReturnType<typeof getContactId>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10ContactIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10ContactId>>>, TError = void>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData>> & Pick<
export function useGetContactIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getContactId>>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10ContactId>>,
Awaited<ReturnType<typeof getContactId>>,
TError,
Awaited<ReturnType<typeof getApiV10ContactId>>
Awaited<ReturnType<typeof getContactId>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10ContactIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10ContactId>>>, TError = void>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData>>, fetch?: RequestInit}
export function useGetContactIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getContactId>>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get contact by ID
*/
export function useGetApiV10ContactIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10ContactId>>>, TError = void>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData>>, fetch?: RequestInit}
export function useGetContactIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getContactId>>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetApiV10ContactIdInfiniteQueryOptions(id,options)
const queryOptions = getGetContactIdInfiniteQueryOptions(id,options)
const query = useInfiniteQuery(queryOptions, queryClient) as UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
......@@ -176,12 +174,12 @@ export function useGetApiV10ContactIdInfinite<TData = InfiniteData<Awaited<Retur
/**
* @summary Get contact by ID
*/
export const prefetchGetApiV10ContactIdInfiniteQuery = async <TData = Awaited<ReturnType<typeof getApiV10ContactId>>, TError = void>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData>>, fetch?: RequestInit}
export const prefetchGetContactIdInfiniteQuery = async <TData = Awaited<ReturnType<typeof getContactId>>, TError = ErrorType<void>>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetApiV10ContactIdInfiniteQueryOptions(id,options)
const queryOptions = getGetContactIdInfiniteQueryOptions(id,options)
await queryClient.prefetchInfiniteQuery(queryOptions);
......@@ -190,62 +188,62 @@ export const prefetchGetApiV10ContactIdInfiniteQuery = async <TData = Awaited<Re
export const getGetApiV10ContactIdQueryOptions = <TData = Awaited<ReturnType<typeof getApiV10ContactId>>, TError = void>(id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData>>, fetch?: RequestInit}
export const getGetContactIdQueryOptions = <TData = Awaited<ReturnType<typeof getContactId>>, TError = ErrorType<void>>(id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, fetch: fetchOptions} = options ?? {};
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetApiV10ContactIdQueryKey(id);
const queryKey = queryOptions?.queryKey ?? getGetContactIdQueryKey(id);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getApiV10ContactId>>> = ({ signal }) => getApiV10ContactId(id, { signal, ...fetchOptions });
const queryFn: QueryFunction<Awaited<ReturnType<typeof getContactId>>> = ({ signal }) => getContactId(id, { signal, ...requestOptions });
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetApiV10ContactIdQueryResult = NonNullable<Awaited<ReturnType<typeof getApiV10ContactId>>>
export type GetApiV10ContactIdQueryError = void
export type GetContactIdQueryResult = NonNullable<Awaited<ReturnType<typeof getContactId>>>
export type GetContactIdQueryError = ErrorType<void>
export function useGetApiV10ContactId<TData = Awaited<ReturnType<typeof getApiV10ContactId>>, TError = void>(
id: string, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData>> & Pick<
export function useGetContactId<TData = Awaited<ReturnType<typeof getContactId>>, TError = ErrorType<void>>(
id: string, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10ContactId>>,
Awaited<ReturnType<typeof getContactId>>,
TError,
Awaited<ReturnType<typeof getApiV10ContactId>>
Awaited<ReturnType<typeof getContactId>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10ContactId<TData = Awaited<ReturnType<typeof getApiV10ContactId>>, TError = void>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData>> & Pick<
export function useGetContactId<TData = Awaited<ReturnType<typeof getContactId>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10ContactId>>,
Awaited<ReturnType<typeof getContactId>>,
TError,
Awaited<ReturnType<typeof getApiV10ContactId>>
Awaited<ReturnType<typeof getContactId>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10ContactId<TData = Awaited<ReturnType<typeof getApiV10ContactId>>, TError = void>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData>>, fetch?: RequestInit}
export function useGetContactId<TData = Awaited<ReturnType<typeof getContactId>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get contact by ID
*/
export function useGetApiV10ContactId<TData = Awaited<ReturnType<typeof getApiV10ContactId>>, TError = void>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData>>, fetch?: RequestInit}
export function useGetContactId<TData = Awaited<ReturnType<typeof getContactId>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetApiV10ContactIdQueryOptions(id,options)
const queryOptions = getGetContactIdQueryOptions(id,options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
......@@ -257,12 +255,12 @@ export function useGetApiV10ContactId<TData = Awaited<ReturnType<typeof getApiV1
/**
* @summary Get contact by ID
*/
export const prefetchGetApiV10ContactIdQuery = async <TData = Awaited<ReturnType<typeof getApiV10ContactId>>, TError = void>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10ContactId>>, TError, TData>>, fetch?: RequestInit}
export const prefetchGetContactIdQuery = async <TData = Awaited<ReturnType<typeof getContactId>>, TError = ErrorType<void>>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getContactId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetApiV10ContactIdQueryOptions(id,options)
const queryOptions = getGetContactIdQueryOptions(id,options)
await queryClient.prefetchQuery(queryOptions);
......@@ -275,37 +273,37 @@ export const prefetchGetApiV10ContactIdQuery = async <TData = Awaited<ReturnType
* Update a single contact record by its ID
* @summary Update contact by ID
*/
export type putApiV10ContactIdResponse200 = {
data: PutApiV10ContactId200
export type putContactIdResponse200 = {
data: PutContactId200
status: 200
}
export type putApiV10ContactIdResponse404 = {
export type putContactIdResponse404 = {
data: void
status: 404
}
export type putApiV10ContactIdResponseSuccess = (putApiV10ContactIdResponse200) & {
export type putContactIdResponseSuccess = (putContactIdResponse200) & {
headers: Headers;
};
export type putApiV10ContactIdResponseError = (putApiV10ContactIdResponse404) & {
export type putContactIdResponseError = (putContactIdResponse404) & {
headers: Headers;
};
export type putApiV10ContactIdResponse = (putApiV10ContactIdResponseSuccess | putApiV10ContactIdResponseError)
export type putContactIdResponse = (putContactIdResponseSuccess | putContactIdResponseError)
export const getPutApiV10ContactIdUrl = (id: string,) => {
export const getPutContactIdUrl = (id: string,) => {
return `/api/v1.0/contact/${id}`
return `/contact/${id}`
}
export const putApiV10ContactId = async (id: string,
contactMutate: ContactMutate, options?: RequestInit): Promise<putApiV10ContactIdResponse> => {
export const putContactId = async (id: string,
contactMutate: ContactMutate, options?: RequestInit): Promise<putContactIdResponse> => {
const res = await fetch(getPutApiV10ContactIdUrl(id),
return useCustomClient<putContactIdResponse>(getPutContactIdUrl(id),
{
...options,
method: 'PUT',
......@@ -313,35 +311,29 @@ export const putApiV10ContactId = async (id: string,
body: JSON.stringify(
contactMutate,)
}
)
);}
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: putApiV10ContactIdResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as putApiV10ContactIdResponse
}
export const getPutContactIdMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putContactId>>, TError,{id: string;data: BodyType<ContactMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof putContactId>>, TError,{id: string;data: BodyType<ContactMutate>}, TContext> => {
export const getPutApiV10ContactIdMutationOptions = <TError = void,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putApiV10ContactId>>, TError,{id: string;data: ContactMutate}, TContext>, fetch?: RequestInit}
): UseMutationOptions<Awaited<ReturnType<typeof putApiV10ContactId>>, TError,{id: string;data: ContactMutate}, TContext> => {
const mutationKey = ['putApiV10ContactId'];
const {mutation: mutationOptions, fetch: fetchOptions} = options ?
const mutationKey = ['putContactId'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, fetch: undefined};
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof putApiV10ContactId>>, {id: string;data: ContactMutate}> = (props) => {
const mutationFn: MutationFunction<Awaited<ReturnType<typeof putContactId>>, {id: string;data: BodyType<ContactMutate>}> = (props) => {
const {id,data} = props ?? {};
return putApiV10ContactId(id,data,fetchOptions)
return putContactId(id,data,requestOptions)
}
......@@ -349,23 +341,23 @@ const {mutation: mutationOptions, fetch: fetchOptions} = options ?
return { mutationFn, ...mutationOptions }}
export type PutApiV10ContactIdMutationResult = NonNullable<Awaited<ReturnType<typeof putApiV10ContactId>>>
export type PutApiV10ContactIdMutationBody = ContactMutate
export type PutApiV10ContactIdMutationError = void
export type PutContactIdMutationResult = NonNullable<Awaited<ReturnType<typeof putContactId>>>
export type PutContactIdMutationBody = BodyType<ContactMutate>
export type PutContactIdMutationError = ErrorType<void>
/**
* @summary Update contact by ID
*/
export const usePutApiV10ContactId = <TError = void,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putApiV10ContactId>>, TError,{id: string;data: ContactMutate}, TContext>, fetch?: RequestInit}
export const usePutContactId = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putContactId>>, TError,{id: string;data: BodyType<ContactMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof putApiV10ContactId>>,
Awaited<ReturnType<typeof putContactId>>,
TError,
{id: string;data: ContactMutate},
{id: string;data: BodyType<ContactMutate>},
TContext
> => {
const mutationOptions = getPutApiV10ContactIdMutationOptions(options);
const mutationOptions = getPutContactIdMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
......@@ -373,71 +365,65 @@ export const usePutApiV10ContactId = <TError = void,
* Delete a single contact record by its ID
* @summary Delete contact by ID
*/
export type deleteApiV10ContactIdResponse200 = {
data: DeleteApiV10ContactId200
export type deleteContactIdResponse200 = {
data: DeleteContactId200
status: 200
}
export type deleteApiV10ContactIdResponse404 = {
export type deleteContactIdResponse404 = {
data: void
status: 404
}
export type deleteApiV10ContactIdResponseSuccess = (deleteApiV10ContactIdResponse200) & {
export type deleteContactIdResponseSuccess = (deleteContactIdResponse200) & {
headers: Headers;
};
export type deleteApiV10ContactIdResponseError = (deleteApiV10ContactIdResponse404) & {
export type deleteContactIdResponseError = (deleteContactIdResponse404) & {
headers: Headers;
};
export type deleteApiV10ContactIdResponse = (deleteApiV10ContactIdResponseSuccess | deleteApiV10ContactIdResponseError)
export type deleteContactIdResponse = (deleteContactIdResponseSuccess | deleteContactIdResponseError)
export const getDeleteApiV10ContactIdUrl = (id: string,) => {
export const getDeleteContactIdUrl = (id: string,) => {
return `/api/v1.0/contact/${id}`
return `/contact/${id}`
}
export const deleteApiV10ContactId = async (id: string, options?: RequestInit): Promise<deleteApiV10ContactIdResponse> => {
export const deleteContactId = async (id: string, options?: RequestInit): Promise<deleteContactIdResponse> => {
const res = await fetch(getDeleteApiV10ContactIdUrl(id),
return useCustomClient<deleteContactIdResponse>(getDeleteContactIdUrl(id),
{
...options,
method: 'DELETE'
}
)
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: deleteApiV10ContactIdResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as deleteApiV10ContactIdResponse
}
);}
export const getDeleteApiV10ContactIdMutationOptions = <TError = void,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteApiV10ContactId>>, TError,{id: string}, TContext>, fetch?: RequestInit}
): UseMutationOptions<Awaited<ReturnType<typeof deleteApiV10ContactId>>, TError,{id: string}, TContext> => {
export const getDeleteContactIdMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteContactId>>, TError,{id: string}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof deleteContactId>>, TError,{id: string}, TContext> => {
const mutationKey = ['deleteApiV10ContactId'];
const {mutation: mutationOptions, fetch: fetchOptions} = options ?
const mutationKey = ['deleteContactId'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, fetch: undefined};
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteApiV10ContactId>>, {id: string}> = (props) => {
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteContactId>>, {id: string}> = (props) => {
const {id} = props ?? {};
return deleteApiV10ContactId(id,fetchOptions)
return deleteContactId(id,requestOptions)
}
......@@ -445,23 +431,23 @@ const {mutation: mutationOptions, fetch: fetchOptions} = options ?
return { mutationFn, ...mutationOptions }}
export type DeleteApiV10ContactIdMutationResult = NonNullable<Awaited<ReturnType<typeof deleteApiV10ContactId>>>
export type DeleteContactIdMutationResult = NonNullable<Awaited<ReturnType<typeof deleteContactId>>>
export type DeleteApiV10ContactIdMutationError = void
export type DeleteContactIdMutationError = ErrorType<void>
/**
* @summary Delete contact by ID
*/
export const useDeleteApiV10ContactId = <TError = void,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteApiV10ContactId>>, TError,{id: string}, TContext>, fetch?: RequestInit}
export const useDeleteContactId = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteContactId>>, TError,{id: string}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof deleteApiV10ContactId>>,
Awaited<ReturnType<typeof deleteContactId>>,
TError,
{id: string},
TContext
> => {
const mutationOptions = getDeleteApiV10ContactIdMutationOptions(options);
const mutationOptions = getDeleteContactIdMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
......@@ -469,19 +455,19 @@ export const useDeleteApiV10ContactId = <TError = void,
* Retrieve a list of contact with pagination, filtering and sorting
* @summary Get all contact
*/
export type getApiV10ContactResponse200 = {
export type getContactResponse200 = {
data: ResponseGetAllData
status: 200
}
export type getApiV10ContactResponseSuccess = (getApiV10ContactResponse200) & {
export type getContactResponseSuccess = (getContactResponse200) & {
headers: Headers;
};
;
export type getApiV10ContactResponse = (getApiV10ContactResponseSuccess)
export type getContactResponse = (getContactResponseSuccess)
export const getGetApiV10ContactUrl = (params?: GetApiV10ContactParams,) => {
export const getGetContactUrl = (params?: GetContactParams,) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
......@@ -493,99 +479,93 @@ export const getGetApiV10ContactUrl = (params?: GetApiV10ContactParams,) => {
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0 ? `/api/v1.0/contact?${stringifiedParams}` : `/api/v1.0/contact`
return stringifiedParams.length > 0 ? `/contact?${stringifiedParams}` : `/contact`
}
export const getApiV10Contact = async (params?: GetApiV10ContactParams, options?: RequestInit): Promise<getApiV10ContactResponse> => {
export const getContact = async (params?: GetContactParams, options?: RequestInit): Promise<getContactResponse> => {
const res = await fetch(getGetApiV10ContactUrl(params),
return useCustomClient<getContactResponse>(getGetContactUrl(params),
{
...options,
method: 'GET'
}
)
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: getApiV10ContactResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as getApiV10ContactResponse
}
);}
export const getGetApiV10ContactInfiniteQueryKey = (params?: GetApiV10ContactParams,) => {
export const getGetContactInfiniteQueryKey = (params?: GetContactParams,) => {
return [
'infinite', `/api/v1.0/contact`, ...(params ? [params]: [])
'infinite', `/contact`, ...(params ? [params]: [])
] as const;
}
export const getGetApiV10ContactQueryKey = (params?: GetApiV10ContactParams,) => {
export const getGetContactQueryKey = (params?: GetContactParams,) => {
return [
`/api/v1.0/contact`, ...(params ? [params]: [])
`/contact`, ...(params ? [params]: [])
] as const;
}
export const getGetApiV10ContactInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getApiV10Contact>>>, TError = unknown>(params?: GetApiV10ContactParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData>>, fetch?: RequestInit}
export const getGetContactInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getContact>>>, TError = ErrorType<unknown>>(params?: GetContactParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, fetch: fetchOptions} = options ?? {};
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetApiV10ContactInfiniteQueryKey(params);
const queryKey = queryOptions?.queryKey ?? getGetContactInfiniteQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getApiV10Contact>>> = ({ signal }) => getApiV10Contact(params, { signal, ...fetchOptions });
const queryFn: QueryFunction<Awaited<ReturnType<typeof getContact>>> = ({ signal }) => getContact(params, { signal, ...requestOptions });
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetApiV10ContactInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getApiV10Contact>>>
export type GetApiV10ContactInfiniteQueryError = unknown
export type GetContactInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getContact>>>
export type GetContactInfiniteQueryError = ErrorType<unknown>
export function useGetApiV10ContactInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10Contact>>>, TError = unknown>(
params: undefined | GetApiV10ContactParams, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData>> & Pick<
export function useGetContactInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getContact>>>, TError = ErrorType<unknown>>(
params: undefined | GetContactParams, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10Contact>>,
Awaited<ReturnType<typeof getContact>>,
TError,
Awaited<ReturnType<typeof getApiV10Contact>>
Awaited<ReturnType<typeof getContact>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10ContactInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10Contact>>>, TError = unknown>(
params?: GetApiV10ContactParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData>> & Pick<
export function useGetContactInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getContact>>>, TError = ErrorType<unknown>>(
params?: GetContactParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10Contact>>,
Awaited<ReturnType<typeof getContact>>,
TError,
Awaited<ReturnType<typeof getApiV10Contact>>
Awaited<ReturnType<typeof getContact>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10ContactInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10Contact>>>, TError = unknown>(
params?: GetApiV10ContactParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData>>, fetch?: RequestInit}
export function useGetContactInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getContact>>>, TError = ErrorType<unknown>>(
params?: GetContactParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get all contact
*/
export function useGetApiV10ContactInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10Contact>>>, TError = unknown>(
params?: GetApiV10ContactParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData>>, fetch?: RequestInit}
export function useGetContactInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getContact>>>, TError = ErrorType<unknown>>(
params?: GetContactParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetApiV10ContactInfiniteQueryOptions(params,options)
const queryOptions = getGetContactInfiniteQueryOptions(params,options)
const query = useInfiniteQuery(queryOptions, queryClient) as UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
......@@ -597,12 +577,12 @@ export function useGetApiV10ContactInfinite<TData = InfiniteData<Awaited<ReturnT
/**
* @summary Get all contact
*/
export const prefetchGetApiV10ContactInfiniteQuery = async <TData = Awaited<ReturnType<typeof getApiV10Contact>>, TError = unknown>(
queryClient: QueryClient, params?: GetApiV10ContactParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData>>, fetch?: RequestInit}
export const prefetchGetContactInfiniteQuery = async <TData = Awaited<ReturnType<typeof getContact>>, TError = ErrorType<unknown>>(
queryClient: QueryClient, params?: GetContactParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetApiV10ContactInfiniteQueryOptions(params,options)
const queryOptions = getGetContactInfiniteQueryOptions(params,options)
await queryClient.prefetchInfiniteQuery(queryOptions);
......@@ -611,62 +591,62 @@ export const prefetchGetApiV10ContactInfiniteQuery = async <TData = Awaited<Retu
export const getGetApiV10ContactQueryOptions = <TData = Awaited<ReturnType<typeof getApiV10Contact>>, TError = unknown>(params?: GetApiV10ContactParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData>>, fetch?: RequestInit}
export const getGetContactQueryOptions = <TData = Awaited<ReturnType<typeof getContact>>, TError = ErrorType<unknown>>(params?: GetContactParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, fetch: fetchOptions} = options ?? {};
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetApiV10ContactQueryKey(params);
const queryKey = queryOptions?.queryKey ?? getGetContactQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getApiV10Contact>>> = ({ signal }) => getApiV10Contact(params, { signal, ...fetchOptions });
const queryFn: QueryFunction<Awaited<ReturnType<typeof getContact>>> = ({ signal }) => getContact(params, { signal, ...requestOptions });
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetApiV10ContactQueryResult = NonNullable<Awaited<ReturnType<typeof getApiV10Contact>>>
export type GetApiV10ContactQueryError = unknown
export type GetContactQueryResult = NonNullable<Awaited<ReturnType<typeof getContact>>>
export type GetContactQueryError = ErrorType<unknown>
export function useGetApiV10Contact<TData = Awaited<ReturnType<typeof getApiV10Contact>>, TError = unknown>(
params: undefined | GetApiV10ContactParams, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData>> & Pick<
export function useGetContact<TData = Awaited<ReturnType<typeof getContact>>, TError = ErrorType<unknown>>(
params: undefined | GetContactParams, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10Contact>>,
Awaited<ReturnType<typeof getContact>>,
TError,
Awaited<ReturnType<typeof getApiV10Contact>>
Awaited<ReturnType<typeof getContact>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10Contact<TData = Awaited<ReturnType<typeof getApiV10Contact>>, TError = unknown>(
params?: GetApiV10ContactParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData>> & Pick<
export function useGetContact<TData = Awaited<ReturnType<typeof getContact>>, TError = ErrorType<unknown>>(
params?: GetContactParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10Contact>>,
Awaited<ReturnType<typeof getContact>>,
TError,
Awaited<ReturnType<typeof getApiV10Contact>>
Awaited<ReturnType<typeof getContact>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10Contact<TData = Awaited<ReturnType<typeof getApiV10Contact>>, TError = unknown>(
params?: GetApiV10ContactParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData>>, fetch?: RequestInit}
export function useGetContact<TData = Awaited<ReturnType<typeof getContact>>, TError = ErrorType<unknown>>(
params?: GetContactParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get all contact
*/
export function useGetApiV10Contact<TData = Awaited<ReturnType<typeof getApiV10Contact>>, TError = unknown>(
params?: GetApiV10ContactParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData>>, fetch?: RequestInit}
export function useGetContact<TData = Awaited<ReturnType<typeof getContact>>, TError = ErrorType<unknown>>(
params?: GetContactParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetApiV10ContactQueryOptions(params,options)
const queryOptions = getGetContactQueryOptions(params,options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
......@@ -678,12 +658,12 @@ export function useGetApiV10Contact<TData = Awaited<ReturnType<typeof getApiV10C
/**
* @summary Get all contact
*/
export const prefetchGetApiV10ContactQuery = async <TData = Awaited<ReturnType<typeof getApiV10Contact>>, TError = unknown>(
queryClient: QueryClient, params?: GetApiV10ContactParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10Contact>>, TError, TData>>, fetch?: RequestInit}
export const prefetchGetContactQuery = async <TData = Awaited<ReturnType<typeof getContact>>, TError = ErrorType<unknown>>(
queryClient: QueryClient, params?: GetContactParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getContact>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetApiV10ContactQueryOptions(params,options)
const queryOptions = getGetContactQueryOptions(params,options)
await queryClient.prefetchQuery(queryOptions);
......@@ -696,29 +676,29 @@ export const prefetchGetApiV10ContactQuery = async <TData = Awaited<ReturnType<t
* Create a new contact record
* @summary Create a contact
*/
export type postApiV10ContactResponse200 = {
data: PostApiV10Contact200
export type postContactResponse200 = {
data: PostContact200
status: 200
}
export type postApiV10ContactResponseSuccess = (postApiV10ContactResponse200) & {
export type postContactResponseSuccess = (postContactResponse200) & {
headers: Headers;
};
;
export type postApiV10ContactResponse = (postApiV10ContactResponseSuccess)
export type postContactResponse = (postContactResponseSuccess)
export const getPostApiV10ContactUrl = () => {
export const getPostContactUrl = () => {
return `/api/v1.0/contact`
return `/contact`
}
export const postApiV10Contact = async (contactMutate: ContactMutate, options?: RequestInit): Promise<postApiV10ContactResponse> => {
export const postContact = async (contactMutate: ContactMutate, options?: RequestInit): Promise<postContactResponse> => {
const res = await fetch(getPostApiV10ContactUrl(),
return useCustomClient<postContactResponse>(getPostContactUrl(),
{
...options,
method: 'POST',
......@@ -726,35 +706,29 @@ export const postApiV10Contact = async (contactMutate: ContactMutate, options?:
body: JSON.stringify(
contactMutate,)
}
)
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: postApiV10ContactResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as postApiV10ContactResponse
}
);}
export const getPostApiV10ContactMutationOptions = <TError = unknown,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postApiV10Contact>>, TError,{data: ContactMutate}, TContext>, fetch?: RequestInit}
): UseMutationOptions<Awaited<ReturnType<typeof postApiV10Contact>>, TError,{data: ContactMutate}, TContext> => {
export const getPostContactMutationOptions = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postContact>>, TError,{data: BodyType<ContactMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof postContact>>, TError,{data: BodyType<ContactMutate>}, TContext> => {
const mutationKey = ['postApiV10Contact'];
const {mutation: mutationOptions, fetch: fetchOptions} = options ?
const mutationKey = ['postContact'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, fetch: undefined};
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof postApiV10Contact>>, {data: ContactMutate}> = (props) => {
const mutationFn: MutationFunction<Awaited<ReturnType<typeof postContact>>, {data: BodyType<ContactMutate>}> = (props) => {
const {data} = props ?? {};
return postApiV10Contact(data,fetchOptions)
return postContact(data,requestOptions)
}
......@@ -762,23 +736,23 @@ const {mutation: mutationOptions, fetch: fetchOptions} = options ?
return { mutationFn, ...mutationOptions }}
export type PostApiV10ContactMutationResult = NonNullable<Awaited<ReturnType<typeof postApiV10Contact>>>
export type PostApiV10ContactMutationBody = ContactMutate
export type PostApiV10ContactMutationError = unknown
export type PostContactMutationResult = NonNullable<Awaited<ReturnType<typeof postContact>>>
export type PostContactMutationBody = BodyType<ContactMutate>
export type PostContactMutationError = ErrorType<unknown>
/**
* @summary Create a contact
*/
export const usePostApiV10Contact = <TError = unknown,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postApiV10Contact>>, TError,{data: ContactMutate}, TContext>, fetch?: RequestInit}
export const usePostContact = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postContact>>, TError,{data: BodyType<ContactMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof postApiV10Contact>>,
Awaited<ReturnType<typeof postContact>>,
TError,
{data: ContactMutate},
{data: BodyType<ContactMutate>},
TContext
> => {
const mutationOptions = getPostApiV10ContactMutationOptions(options);
const mutationOptions = getPostContactMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import {
useInfiniteQuery,
useMutation,
useQuery
} from '@tanstack/react-query';
import type {
DataTag,
DefinedInitialDataOptions,
DefinedUseInfiniteQueryResult,
DefinedUseQueryResult,
InfiniteData,
MutationFunction,
QueryClient,
QueryFunction,
QueryKey,
UndefinedInitialDataOptions,
UseInfiniteQueryOptions,
UseInfiniteQueryResult,
UseMutationOptions,
UseMutationResult,
UseQueryOptions,
UseQueryResult
} from '@tanstack/react-query';
import type {
GetNewsletterSubscriptionParams,
NewsletterSubscriptionMutate,
NewsletterSubscriptionUpdate,
PatchNewsletterSubscriptionId200,
PostNewsletterSubscription200,
ResponseGetAllData
} from '../models';
import { useCustomClient } from '../mutator/custom-client';
import type { ErrorType , BodyType } from '../mutator/custom-client';
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
/**
* Update seen status of a newsletter subscription email
* @summary Update newsletter subscription status
*/
export type patchNewsletterSubscriptionIdResponse200 = {
data: PatchNewsletterSubscriptionId200
status: 200
}
export type patchNewsletterSubscriptionIdResponseSuccess = (patchNewsletterSubscriptionIdResponse200) & {
headers: Headers;
};
;
export type patchNewsletterSubscriptionIdResponse = (patchNewsletterSubscriptionIdResponseSuccess)
export const getPatchNewsletterSubscriptionIdUrl = (id: string,) => {
return `/newsletterSubscription/${id}`
}
export const patchNewsletterSubscriptionId = async (id: string,
newsletterSubscriptionUpdate: NewsletterSubscriptionUpdate, options?: RequestInit): Promise<patchNewsletterSubscriptionIdResponse> => {
return useCustomClient<patchNewsletterSubscriptionIdResponse>(getPatchNewsletterSubscriptionIdUrl(id),
{
...options,
method: 'PATCH',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(
newsletterSubscriptionUpdate,)
}
);}
export const getPatchNewsletterSubscriptionIdMutationOptions = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof patchNewsletterSubscriptionId>>, TError,{id: string;data: BodyType<NewsletterSubscriptionUpdate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof patchNewsletterSubscriptionId>>, TError,{id: string;data: BodyType<NewsletterSubscriptionUpdate>}, TContext> => {
const mutationKey = ['patchNewsletterSubscriptionId'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof patchNewsletterSubscriptionId>>, {id: string;data: BodyType<NewsletterSubscriptionUpdate>}> = (props) => {
const {id,data} = props ?? {};
return patchNewsletterSubscriptionId(id,data,requestOptions)
}
return { mutationFn, ...mutationOptions }}
export type PatchNewsletterSubscriptionIdMutationResult = NonNullable<Awaited<ReturnType<typeof patchNewsletterSubscriptionId>>>
export type PatchNewsletterSubscriptionIdMutationBody = BodyType<NewsletterSubscriptionUpdate>
export type PatchNewsletterSubscriptionIdMutationError = ErrorType<unknown>
/**
* @summary Update newsletter subscription status
*/
export const usePatchNewsletterSubscriptionId = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof patchNewsletterSubscriptionId>>, TError,{id: string;data: BodyType<NewsletterSubscriptionUpdate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof patchNewsletterSubscriptionId>>,
TError,
{id: string;data: BodyType<NewsletterSubscriptionUpdate>},
TContext
> => {
const mutationOptions = getPatchNewsletterSubscriptionIdMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
/**
* Delete a newsletter subscription email
* @summary Delete newsletter subscription
*/
export type deleteNewsletterSubscriptionIdResponse200 = {
data: void
status: 200
}
export type deleteNewsletterSubscriptionIdResponseSuccess = (deleteNewsletterSubscriptionIdResponse200) & {
headers: Headers;
};
;
export type deleteNewsletterSubscriptionIdResponse = (deleteNewsletterSubscriptionIdResponseSuccess)
export const getDeleteNewsletterSubscriptionIdUrl = (id: string,) => {
return `/newsletterSubscription/${id}`
}
export const deleteNewsletterSubscriptionId = async (id: string, options?: RequestInit): Promise<deleteNewsletterSubscriptionIdResponse> => {
return useCustomClient<deleteNewsletterSubscriptionIdResponse>(getDeleteNewsletterSubscriptionIdUrl(id),
{
...options,
method: 'DELETE'
}
);}
export const getDeleteNewsletterSubscriptionIdMutationOptions = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteNewsletterSubscriptionId>>, TError,{id: string}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof deleteNewsletterSubscriptionId>>, TError,{id: string}, TContext> => {
const mutationKey = ['deleteNewsletterSubscriptionId'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteNewsletterSubscriptionId>>, {id: string}> = (props) => {
const {id} = props ?? {};
return deleteNewsletterSubscriptionId(id,requestOptions)
}
return { mutationFn, ...mutationOptions }}
export type DeleteNewsletterSubscriptionIdMutationResult = NonNullable<Awaited<ReturnType<typeof deleteNewsletterSubscriptionId>>>
export type DeleteNewsletterSubscriptionIdMutationError = ErrorType<unknown>
/**
* @summary Delete newsletter subscription
*/
export const useDeleteNewsletterSubscriptionId = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteNewsletterSubscriptionId>>, TError,{id: string}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof deleteNewsletterSubscriptionId>>,
TError,
{id: string},
TContext
> => {
const mutationOptions = getDeleteNewsletterSubscriptionIdMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
/**
* Retrieve newsletter subscription emails with pagination, filtering and sorting
* @summary Get all newsletter subscriptions
*/
export type getNewsletterSubscriptionResponse200 = {
data: ResponseGetAllData
status: 200
}
export type getNewsletterSubscriptionResponseSuccess = (getNewsletterSubscriptionResponse200) & {
headers: Headers;
};
;
export type getNewsletterSubscriptionResponse = (getNewsletterSubscriptionResponseSuccess)
export const getGetNewsletterSubscriptionUrl = (params?: GetNewsletterSubscriptionParams,) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? 'null' : value.toString())
}
});
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0 ? `/newsletterSubscription?${stringifiedParams}` : `/newsletterSubscription`
}
export const getNewsletterSubscription = async (params?: GetNewsletterSubscriptionParams, options?: RequestInit): Promise<getNewsletterSubscriptionResponse> => {
return useCustomClient<getNewsletterSubscriptionResponse>(getGetNewsletterSubscriptionUrl(params),
{
...options,
method: 'GET'
}
);}
export const getGetNewsletterSubscriptionInfiniteQueryKey = (params?: GetNewsletterSubscriptionParams,) => {
return [
'infinite', `/newsletterSubscription`, ...(params ? [params]: [])
] as const;
}
export const getGetNewsletterSubscriptionQueryKey = (params?: GetNewsletterSubscriptionParams,) => {
return [
`/newsletterSubscription`, ...(params ? [params]: [])
] as const;
}
export const getGetNewsletterSubscriptionInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getNewsletterSubscription>>>, TError = ErrorType<unknown>>(params?: GetNewsletterSubscriptionParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetNewsletterSubscriptionInfiniteQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getNewsletterSubscription>>> = ({ signal }) => getNewsletterSubscription(params, { signal, ...requestOptions });
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetNewsletterSubscriptionInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getNewsletterSubscription>>>
export type GetNewsletterSubscriptionInfiniteQueryError = ErrorType<unknown>
export function useGetNewsletterSubscriptionInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getNewsletterSubscription>>>, TError = ErrorType<unknown>>(
params: undefined | GetNewsletterSubscriptionParams, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getNewsletterSubscription>>,
TError,
Awaited<ReturnType<typeof getNewsletterSubscription>>
> , 'initialData'
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetNewsletterSubscriptionInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getNewsletterSubscription>>>, TError = ErrorType<unknown>>(
params?: GetNewsletterSubscriptionParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getNewsletterSubscription>>,
TError,
Awaited<ReturnType<typeof getNewsletterSubscription>>
> , 'initialData'
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetNewsletterSubscriptionInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getNewsletterSubscription>>>, TError = ErrorType<unknown>>(
params?: GetNewsletterSubscriptionParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get all newsletter subscriptions
*/
export function useGetNewsletterSubscriptionInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getNewsletterSubscription>>>, TError = ErrorType<unknown>>(
params?: GetNewsletterSubscriptionParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetNewsletterSubscriptionInfiniteQueryOptions(params,options)
const query = useInfiniteQuery(queryOptions, queryClient) as UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary Get all newsletter subscriptions
*/
export const prefetchGetNewsletterSubscriptionInfiniteQuery = async <TData = Awaited<ReturnType<typeof getNewsletterSubscription>>, TError = ErrorType<unknown>>(
queryClient: QueryClient, params?: GetNewsletterSubscriptionParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetNewsletterSubscriptionInfiniteQueryOptions(params,options)
await queryClient.prefetchInfiniteQuery(queryOptions);
return queryClient;
}
export const getGetNewsletterSubscriptionQueryOptions = <TData = Awaited<ReturnType<typeof getNewsletterSubscription>>, TError = ErrorType<unknown>>(params?: GetNewsletterSubscriptionParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetNewsletterSubscriptionQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getNewsletterSubscription>>> = ({ signal }) => getNewsletterSubscription(params, { signal, ...requestOptions });
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetNewsletterSubscriptionQueryResult = NonNullable<Awaited<ReturnType<typeof getNewsletterSubscription>>>
export type GetNewsletterSubscriptionQueryError = ErrorType<unknown>
export function useGetNewsletterSubscription<TData = Awaited<ReturnType<typeof getNewsletterSubscription>>, TError = ErrorType<unknown>>(
params: undefined | GetNewsletterSubscriptionParams, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getNewsletterSubscription>>,
TError,
Awaited<ReturnType<typeof getNewsletterSubscription>>
> , 'initialData'
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetNewsletterSubscription<TData = Awaited<ReturnType<typeof getNewsletterSubscription>>, TError = ErrorType<unknown>>(
params?: GetNewsletterSubscriptionParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getNewsletterSubscription>>,
TError,
Awaited<ReturnType<typeof getNewsletterSubscription>>
> , 'initialData'
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetNewsletterSubscription<TData = Awaited<ReturnType<typeof getNewsletterSubscription>>, TError = ErrorType<unknown>>(
params?: GetNewsletterSubscriptionParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get all newsletter subscriptions
*/
export function useGetNewsletterSubscription<TData = Awaited<ReturnType<typeof getNewsletterSubscription>>, TError = ErrorType<unknown>>(
params?: GetNewsletterSubscriptionParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetNewsletterSubscriptionQueryOptions(params,options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary Get all newsletter subscriptions
*/
export const prefetchGetNewsletterSubscriptionQuery = async <TData = Awaited<ReturnType<typeof getNewsletterSubscription>>, TError = ErrorType<unknown>>(
queryClient: QueryClient, params?: GetNewsletterSubscriptionParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getNewsletterSubscription>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetNewsletterSubscriptionQueryOptions(params,options)
await queryClient.prefetchQuery(queryOptions);
return queryClient;
}
/**
* Register an email to receive information from the website
* @summary Subscribe newsletter email
*/
export type postNewsletterSubscriptionResponse200 = {
data: PostNewsletterSubscription200
status: 200
}
export type postNewsletterSubscriptionResponseSuccess = (postNewsletterSubscriptionResponse200) & {
headers: Headers;
};
;
export type postNewsletterSubscriptionResponse = (postNewsletterSubscriptionResponseSuccess)
export const getPostNewsletterSubscriptionUrl = () => {
return `/newsletterSubscription`
}
export const postNewsletterSubscription = async (newsletterSubscriptionMutate: NewsletterSubscriptionMutate, options?: RequestInit): Promise<postNewsletterSubscriptionResponse> => {
return useCustomClient<postNewsletterSubscriptionResponse>(getPostNewsletterSubscriptionUrl(),
{
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(
newsletterSubscriptionMutate,)
}
);}
export const getPostNewsletterSubscriptionMutationOptions = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postNewsletterSubscription>>, TError,{data: BodyType<NewsletterSubscriptionMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof postNewsletterSubscription>>, TError,{data: BodyType<NewsletterSubscriptionMutate>}, TContext> => {
const mutationKey = ['postNewsletterSubscription'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof postNewsletterSubscription>>, {data: BodyType<NewsletterSubscriptionMutate>}> = (props) => {
const {data} = props ?? {};
return postNewsletterSubscription(data,requestOptions)
}
return { mutationFn, ...mutationOptions }}
export type PostNewsletterSubscriptionMutationResult = NonNullable<Awaited<ReturnType<typeof postNewsletterSubscription>>>
export type PostNewsletterSubscriptionMutationBody = BodyType<NewsletterSubscriptionMutate>
export type PostNewsletterSubscriptionMutationError = ErrorType<unknown>
/**
* @summary Subscribe newsletter email
*/
export const usePostNewsletterSubscription = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postNewsletterSubscription>>, TError,{data: BodyType<NewsletterSubscriptionMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof postNewsletterSubscription>>,
TError,
{data: BodyType<NewsletterSubscriptionMutate>},
TContext
> => {
const mutationOptions = getPostNewsletterSubscriptionMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
\ No newline at end of file
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import {
......@@ -30,137 +30,135 @@ import type {
} from '@tanstack/react-query';
import type {
GetApiV10PageConfigParams,
PostApiV10PageConfigBody,
PutApiV10PageConfigIdBody
GetPageConfigParams,
PostPageConfigBody,
PutPageConfigIdBody
} from '../models';
import { useCustomClient } from '../mutator/custom-client';
import type { ErrorType , BodyType } from '../mutator/custom-client';
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
/**
* Retrieve hierarchical page config by its ID
* @summary Get hierarchical pageConfig by ID
*/
export type getApiV10PageConfigIdResponse200 = {
export type getPageConfigIdResponse200 = {
data: void
status: 200
}
export type getApiV10PageConfigIdResponse404 = {
export type getPageConfigIdResponse404 = {
data: void
status: 404
}
export type getApiV10PageConfigIdResponseSuccess = (getApiV10PageConfigIdResponse200) & {
export type getPageConfigIdResponseSuccess = (getPageConfigIdResponse200) & {
headers: Headers;
};
export type getApiV10PageConfigIdResponseError = (getApiV10PageConfigIdResponse404) & {
export type getPageConfigIdResponseError = (getPageConfigIdResponse404) & {
headers: Headers;
};
export type getApiV10PageConfigIdResponse = (getApiV10PageConfigIdResponseSuccess | getApiV10PageConfigIdResponseError)
export type getPageConfigIdResponse = (getPageConfigIdResponseSuccess | getPageConfigIdResponseError)
export const getGetApiV10PageConfigIdUrl = (id: string,) => {
export const getGetPageConfigIdUrl = (id: string,) => {
return `/api/v1.0/pageConfig/${id}`
return `/pageConfig/${id}`
}
export const getApiV10PageConfigId = async (id: string, options?: RequestInit): Promise<getApiV10PageConfigIdResponse> => {
export const getPageConfigId = async (id: string, options?: RequestInit): Promise<getPageConfigIdResponse> => {
const res = await fetch(getGetApiV10PageConfigIdUrl(id),
return useCustomClient<getPageConfigIdResponse>(getGetPageConfigIdUrl(id),
{
...options,
method: 'GET'
}
)
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: getApiV10PageConfigIdResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as getApiV10PageConfigIdResponse
}
);}
export const getGetApiV10PageConfigIdInfiniteQueryKey = (id?: string,) => {
export const getGetPageConfigIdInfiniteQueryKey = (id?: string,) => {
return [
'infinite', `/api/v1.0/pageConfig/${id}`
'infinite', `/pageConfig/${id}`
] as const;
}
export const getGetApiV10PageConfigIdQueryKey = (id?: string,) => {
export const getGetPageConfigIdQueryKey = (id?: string,) => {
return [
`/api/v1.0/pageConfig/${id}`
`/pageConfig/${id}`
] as const;
}
export const getGetApiV10PageConfigIdInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getApiV10PageConfigId>>>, TError = void>(id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData>>, fetch?: RequestInit}
export const getGetPageConfigIdInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getPageConfigId>>>, TError = ErrorType<void>>(id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, fetch: fetchOptions} = options ?? {};
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetApiV10PageConfigIdInfiniteQueryKey(id);
const queryKey = queryOptions?.queryKey ?? getGetPageConfigIdInfiniteQueryKey(id);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getApiV10PageConfigId>>> = ({ signal }) => getApiV10PageConfigId(id, { signal, ...fetchOptions });
const queryFn: QueryFunction<Awaited<ReturnType<typeof getPageConfigId>>> = ({ signal }) => getPageConfigId(id, { signal, ...requestOptions });
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetApiV10PageConfigIdInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getApiV10PageConfigId>>>
export type GetApiV10PageConfigIdInfiniteQueryError = void
export type GetPageConfigIdInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getPageConfigId>>>
export type GetPageConfigIdInfiniteQueryError = ErrorType<void>
export function useGetApiV10PageConfigIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10PageConfigId>>>, TError = void>(
id: string, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData>> & Pick<
export function useGetPageConfigIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getPageConfigId>>>, TError = ErrorType<void>>(
id: string, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10PageConfigId>>,
Awaited<ReturnType<typeof getPageConfigId>>,
TError,
Awaited<ReturnType<typeof getApiV10PageConfigId>>
Awaited<ReturnType<typeof getPageConfigId>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10PageConfigIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10PageConfigId>>>, TError = void>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData>> & Pick<
export function useGetPageConfigIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getPageConfigId>>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10PageConfigId>>,
Awaited<ReturnType<typeof getPageConfigId>>,
TError,
Awaited<ReturnType<typeof getApiV10PageConfigId>>
Awaited<ReturnType<typeof getPageConfigId>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10PageConfigIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10PageConfigId>>>, TError = void>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData>>, fetch?: RequestInit}
export function useGetPageConfigIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getPageConfigId>>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get hierarchical pageConfig by ID
*/
export function useGetApiV10PageConfigIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10PageConfigId>>>, TError = void>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData>>, fetch?: RequestInit}
export function useGetPageConfigIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getPageConfigId>>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetApiV10PageConfigIdInfiniteQueryOptions(id,options)
const queryOptions = getGetPageConfigIdInfiniteQueryOptions(id,options)
const query = useInfiniteQuery(queryOptions, queryClient) as UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
......@@ -172,12 +170,12 @@ export function useGetApiV10PageConfigIdInfinite<TData = InfiniteData<Awaited<Re
/**
* @summary Get hierarchical pageConfig by ID
*/
export const prefetchGetApiV10PageConfigIdInfiniteQuery = async <TData = Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError = void>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData>>, fetch?: RequestInit}
export const prefetchGetPageConfigIdInfiniteQuery = async <TData = Awaited<ReturnType<typeof getPageConfigId>>, TError = ErrorType<void>>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetApiV10PageConfigIdInfiniteQueryOptions(id,options)
const queryOptions = getGetPageConfigIdInfiniteQueryOptions(id,options)
await queryClient.prefetchInfiniteQuery(queryOptions);
......@@ -186,62 +184,62 @@ export const prefetchGetApiV10PageConfigIdInfiniteQuery = async <TData = Awaited
export const getGetApiV10PageConfigIdQueryOptions = <TData = Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError = void>(id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData>>, fetch?: RequestInit}
export const getGetPageConfigIdQueryOptions = <TData = Awaited<ReturnType<typeof getPageConfigId>>, TError = ErrorType<void>>(id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, fetch: fetchOptions} = options ?? {};
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetApiV10PageConfigIdQueryKey(id);
const queryKey = queryOptions?.queryKey ?? getGetPageConfigIdQueryKey(id);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getApiV10PageConfigId>>> = ({ signal }) => getApiV10PageConfigId(id, { signal, ...fetchOptions });
const queryFn: QueryFunction<Awaited<ReturnType<typeof getPageConfigId>>> = ({ signal }) => getPageConfigId(id, { signal, ...requestOptions });
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetApiV10PageConfigIdQueryResult = NonNullable<Awaited<ReturnType<typeof getApiV10PageConfigId>>>
export type GetApiV10PageConfigIdQueryError = void
export type GetPageConfigIdQueryResult = NonNullable<Awaited<ReturnType<typeof getPageConfigId>>>
export type GetPageConfigIdQueryError = ErrorType<void>
export function useGetApiV10PageConfigId<TData = Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError = void>(
id: string, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData>> & Pick<
export function useGetPageConfigId<TData = Awaited<ReturnType<typeof getPageConfigId>>, TError = ErrorType<void>>(
id: string, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10PageConfigId>>,
Awaited<ReturnType<typeof getPageConfigId>>,
TError,
Awaited<ReturnType<typeof getApiV10PageConfigId>>
Awaited<ReturnType<typeof getPageConfigId>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10PageConfigId<TData = Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError = void>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData>> & Pick<
export function useGetPageConfigId<TData = Awaited<ReturnType<typeof getPageConfigId>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10PageConfigId>>,
Awaited<ReturnType<typeof getPageConfigId>>,
TError,
Awaited<ReturnType<typeof getApiV10PageConfigId>>
Awaited<ReturnType<typeof getPageConfigId>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10PageConfigId<TData = Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError = void>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData>>, fetch?: RequestInit}
export function useGetPageConfigId<TData = Awaited<ReturnType<typeof getPageConfigId>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get hierarchical pageConfig by ID
*/
export function useGetApiV10PageConfigId<TData = Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError = void>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData>>, fetch?: RequestInit}
export function useGetPageConfigId<TData = Awaited<ReturnType<typeof getPageConfigId>>, TError = ErrorType<void>>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetApiV10PageConfigIdQueryOptions(id,options)
const queryOptions = getGetPageConfigIdQueryOptions(id,options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
......@@ -253,12 +251,12 @@ export function useGetApiV10PageConfigId<TData = Awaited<ReturnType<typeof getAp
/**
* @summary Get hierarchical pageConfig by ID
*/
export const prefetchGetApiV10PageConfigIdQuery = async <TData = Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError = void>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfigId>>, TError, TData>>, fetch?: RequestInit}
export const prefetchGetPageConfigIdQuery = async <TData = Awaited<ReturnType<typeof getPageConfigId>>, TError = ErrorType<void>>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getPageConfigId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetApiV10PageConfigIdQueryOptions(id,options)
const queryOptions = getGetPageConfigIdQueryOptions(id,options)
await queryClient.prefetchQuery(queryOptions);
......@@ -271,73 +269,67 @@ export const prefetchGetApiV10PageConfigIdQuery = async <TData = Awaited<ReturnT
* Update a single pageConfig record by its ID. level is computed if parent_id changes and must not be sent.
* @summary Update pageConfig by ID
*/
export type putApiV10PageConfigIdResponse200 = {
export type putPageConfigIdResponse200 = {
data: void
status: 200
}
export type putApiV10PageConfigIdResponse404 = {
export type putPageConfigIdResponse404 = {
data: void
status: 404
}
export type putApiV10PageConfigIdResponseSuccess = (putApiV10PageConfigIdResponse200) & {
export type putPageConfigIdResponseSuccess = (putPageConfigIdResponse200) & {
headers: Headers;
};
export type putApiV10PageConfigIdResponseError = (putApiV10PageConfigIdResponse404) & {
export type putPageConfigIdResponseError = (putPageConfigIdResponse404) & {
headers: Headers;
};
export type putApiV10PageConfigIdResponse = (putApiV10PageConfigIdResponseSuccess | putApiV10PageConfigIdResponseError)
export type putPageConfigIdResponse = (putPageConfigIdResponseSuccess | putPageConfigIdResponseError)
export const getPutApiV10PageConfigIdUrl = (id: string,) => {
export const getPutPageConfigIdUrl = (id: string,) => {
return `/api/v1.0/pageConfig/${id}`
return `/pageConfig/${id}`
}
export const putApiV10PageConfigId = async (id: string,
putApiV10PageConfigIdBody: PutApiV10PageConfigIdBody, options?: RequestInit): Promise<putApiV10PageConfigIdResponse> => {
export const putPageConfigId = async (id: string,
putPageConfigIdBody: PutPageConfigIdBody, options?: RequestInit): Promise<putPageConfigIdResponse> => {
const res = await fetch(getPutApiV10PageConfigIdUrl(id),
return useCustomClient<putPageConfigIdResponse>(getPutPageConfigIdUrl(id),
{
...options,
method: 'PUT',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(
putApiV10PageConfigIdBody,)
putPageConfigIdBody,)
}
)
);}
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: putApiV10PageConfigIdResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as putApiV10PageConfigIdResponse
}
export const getPutPageConfigIdMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putPageConfigId>>, TError,{id: string;data: BodyType<PutPageConfigIdBody>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof putPageConfigId>>, TError,{id: string;data: BodyType<PutPageConfigIdBody>}, TContext> => {
export const getPutApiV10PageConfigIdMutationOptions = <TError = void,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putApiV10PageConfigId>>, TError,{id: string;data: PutApiV10PageConfigIdBody}, TContext>, fetch?: RequestInit}
): UseMutationOptions<Awaited<ReturnType<typeof putApiV10PageConfigId>>, TError,{id: string;data: PutApiV10PageConfigIdBody}, TContext> => {
const mutationKey = ['putApiV10PageConfigId'];
const {mutation: mutationOptions, fetch: fetchOptions} = options ?
const mutationKey = ['putPageConfigId'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, fetch: undefined};
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof putApiV10PageConfigId>>, {id: string;data: PutApiV10PageConfigIdBody}> = (props) => {
const mutationFn: MutationFunction<Awaited<ReturnType<typeof putPageConfigId>>, {id: string;data: BodyType<PutPageConfigIdBody>}> = (props) => {
const {id,data} = props ?? {};
return putApiV10PageConfigId(id,data,fetchOptions)
return putPageConfigId(id,data,requestOptions)
}
......@@ -345,23 +337,23 @@ const {mutation: mutationOptions, fetch: fetchOptions} = options ?
return { mutationFn, ...mutationOptions }}
export type PutApiV10PageConfigIdMutationResult = NonNullable<Awaited<ReturnType<typeof putApiV10PageConfigId>>>
export type PutApiV10PageConfigIdMutationBody = PutApiV10PageConfigIdBody
export type PutApiV10PageConfigIdMutationError = void
export type PutPageConfigIdMutationResult = NonNullable<Awaited<ReturnType<typeof putPageConfigId>>>
export type PutPageConfigIdMutationBody = BodyType<PutPageConfigIdBody>
export type PutPageConfigIdMutationError = ErrorType<void>
/**
* @summary Update pageConfig by ID
*/
export const usePutApiV10PageConfigId = <TError = void,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putApiV10PageConfigId>>, TError,{id: string;data: PutApiV10PageConfigIdBody}, TContext>, fetch?: RequestInit}
export const usePutPageConfigId = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putPageConfigId>>, TError,{id: string;data: BodyType<PutPageConfigIdBody>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof putApiV10PageConfigId>>,
Awaited<ReturnType<typeof putPageConfigId>>,
TError,
{id: string;data: PutApiV10PageConfigIdBody},
{id: string;data: BodyType<PutPageConfigIdBody>},
TContext
> => {
const mutationOptions = getPutApiV10PageConfigIdMutationOptions(options);
const mutationOptions = getPutPageConfigIdMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
......@@ -369,71 +361,65 @@ export const usePutApiV10PageConfigId = <TError = void,
* Delete a single pageConfig record by its ID
* @summary Delete pageConfig by ID
*/
export type deleteApiV10PageConfigIdResponse200 = {
export type deletePageConfigIdResponse200 = {
data: void
status: 200
}
export type deleteApiV10PageConfigIdResponse404 = {
export type deletePageConfigIdResponse404 = {
data: void
status: 404
}
export type deleteApiV10PageConfigIdResponseSuccess = (deleteApiV10PageConfigIdResponse200) & {
export type deletePageConfigIdResponseSuccess = (deletePageConfigIdResponse200) & {
headers: Headers;
};
export type deleteApiV10PageConfigIdResponseError = (deleteApiV10PageConfigIdResponse404) & {
export type deletePageConfigIdResponseError = (deletePageConfigIdResponse404) & {
headers: Headers;
};
export type deleteApiV10PageConfigIdResponse = (deleteApiV10PageConfigIdResponseSuccess | deleteApiV10PageConfigIdResponseError)
export type deletePageConfigIdResponse = (deletePageConfigIdResponseSuccess | deletePageConfigIdResponseError)
export const getDeleteApiV10PageConfigIdUrl = (id: string,) => {
export const getDeletePageConfigIdUrl = (id: string,) => {
return `/api/v1.0/pageConfig/${id}`
return `/pageConfig/${id}`
}
export const deleteApiV10PageConfigId = async (id: string, options?: RequestInit): Promise<deleteApiV10PageConfigIdResponse> => {
export const deletePageConfigId = async (id: string, options?: RequestInit): Promise<deletePageConfigIdResponse> => {
const res = await fetch(getDeleteApiV10PageConfigIdUrl(id),
return useCustomClient<deletePageConfigIdResponse>(getDeletePageConfigIdUrl(id),
{
...options,
method: 'DELETE'
}
)
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: deleteApiV10PageConfigIdResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as deleteApiV10PageConfigIdResponse
}
);}
export const getDeleteApiV10PageConfigIdMutationOptions = <TError = void,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteApiV10PageConfigId>>, TError,{id: string}, TContext>, fetch?: RequestInit}
): UseMutationOptions<Awaited<ReturnType<typeof deleteApiV10PageConfigId>>, TError,{id: string}, TContext> => {
export const getDeletePageConfigIdMutationOptions = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deletePageConfigId>>, TError,{id: string}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof deletePageConfigId>>, TError,{id: string}, TContext> => {
const mutationKey = ['deleteApiV10PageConfigId'];
const {mutation: mutationOptions, fetch: fetchOptions} = options ?
const mutationKey = ['deletePageConfigId'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, fetch: undefined};
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteApiV10PageConfigId>>, {id: string}> = (props) => {
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deletePageConfigId>>, {id: string}> = (props) => {
const {id} = props ?? {};
return deleteApiV10PageConfigId(id,fetchOptions)
return deletePageConfigId(id,requestOptions)
}
......@@ -441,23 +427,23 @@ const {mutation: mutationOptions, fetch: fetchOptions} = options ?
return { mutationFn, ...mutationOptions }}
export type DeleteApiV10PageConfigIdMutationResult = NonNullable<Awaited<ReturnType<typeof deleteApiV10PageConfigId>>>
export type DeletePageConfigIdMutationResult = NonNullable<Awaited<ReturnType<typeof deletePageConfigId>>>
export type DeleteApiV10PageConfigIdMutationError = void
export type DeletePageConfigIdMutationError = ErrorType<void>
/**
* @summary Delete pageConfig by ID
*/
export const useDeleteApiV10PageConfigId = <TError = void,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteApiV10PageConfigId>>, TError,{id: string}, TContext>, fetch?: RequestInit}
export const useDeletePageConfigId = <TError = ErrorType<void>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deletePageConfigId>>, TError,{id: string}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof deleteApiV10PageConfigId>>,
Awaited<ReturnType<typeof deletePageConfigId>>,
TError,
{id: string},
TContext
> => {
const mutationOptions = getDeleteApiV10PageConfigIdMutationOptions(options);
const mutationOptions = getDeletePageConfigIdMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
......@@ -465,19 +451,19 @@ export const useDeleteApiV10PageConfigId = <TError = void,
* Retrieve hierarchical page config by id, static_link, or code. If no parameters are provided, returns the root hierarchical structure.
* @summary Get hierarchical pageConfig
*/
export type getApiV10PageConfigResponse200 = {
export type getPageConfigResponse200 = {
data: void
status: 200
}
export type getApiV10PageConfigResponseSuccess = (getApiV10PageConfigResponse200) & {
export type getPageConfigResponseSuccess = (getPageConfigResponse200) & {
headers: Headers;
};
;
export type getApiV10PageConfigResponse = (getApiV10PageConfigResponseSuccess)
export type getPageConfigResponse = (getPageConfigResponseSuccess)
export const getGetApiV10PageConfigUrl = (params?: GetApiV10PageConfigParams,) => {
export const getGetPageConfigUrl = (params?: GetPageConfigParams,) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
......@@ -489,99 +475,93 @@ export const getGetApiV10PageConfigUrl = (params?: GetApiV10PageConfigParams,) =
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0 ? `/api/v1.0/pageConfig?${stringifiedParams}` : `/api/v1.0/pageConfig`
return stringifiedParams.length > 0 ? `/pageConfig?${stringifiedParams}` : `/pageConfig`
}
export const getApiV10PageConfig = async (params?: GetApiV10PageConfigParams, options?: RequestInit): Promise<getApiV10PageConfigResponse> => {
export const getPageConfig = async (params?: GetPageConfigParams, options?: RequestInit): Promise<getPageConfigResponse> => {
const res = await fetch(getGetApiV10PageConfigUrl(params),
return useCustomClient<getPageConfigResponse>(getGetPageConfigUrl(params),
{
...options,
method: 'GET'
}
)
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: getApiV10PageConfigResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as getApiV10PageConfigResponse
}
);}
export const getGetApiV10PageConfigInfiniteQueryKey = (params?: GetApiV10PageConfigParams,) => {
export const getGetPageConfigInfiniteQueryKey = (params?: GetPageConfigParams,) => {
return [
'infinite', `/api/v1.0/pageConfig`, ...(params ? [params]: [])
'infinite', `/pageConfig`, ...(params ? [params]: [])
] as const;
}
export const getGetApiV10PageConfigQueryKey = (params?: GetApiV10PageConfigParams,) => {
export const getGetPageConfigQueryKey = (params?: GetPageConfigParams,) => {
return [
`/api/v1.0/pageConfig`, ...(params ? [params]: [])
`/pageConfig`, ...(params ? [params]: [])
] as const;
}
export const getGetApiV10PageConfigInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getApiV10PageConfig>>>, TError = unknown>(params?: GetApiV10PageConfigParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData>>, fetch?: RequestInit}
export const getGetPageConfigInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getPageConfig>>>, TError = ErrorType<unknown>>(params?: GetPageConfigParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, fetch: fetchOptions} = options ?? {};
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetApiV10PageConfigInfiniteQueryKey(params);
const queryKey = queryOptions?.queryKey ?? getGetPageConfigInfiniteQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getApiV10PageConfig>>> = ({ signal }) => getApiV10PageConfig(params, { signal, ...fetchOptions });
const queryFn: QueryFunction<Awaited<ReturnType<typeof getPageConfig>>> = ({ signal }) => getPageConfig(params, { signal, ...requestOptions });
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetApiV10PageConfigInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getApiV10PageConfig>>>
export type GetApiV10PageConfigInfiniteQueryError = unknown
export type GetPageConfigInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getPageConfig>>>
export type GetPageConfigInfiniteQueryError = ErrorType<unknown>
export function useGetApiV10PageConfigInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10PageConfig>>>, TError = unknown>(
params: undefined | GetApiV10PageConfigParams, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData>> & Pick<
export function useGetPageConfigInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getPageConfig>>>, TError = ErrorType<unknown>>(
params: undefined | GetPageConfigParams, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10PageConfig>>,
Awaited<ReturnType<typeof getPageConfig>>,
TError,
Awaited<ReturnType<typeof getApiV10PageConfig>>
Awaited<ReturnType<typeof getPageConfig>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10PageConfigInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10PageConfig>>>, TError = unknown>(
params?: GetApiV10PageConfigParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData>> & Pick<
export function useGetPageConfigInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getPageConfig>>>, TError = ErrorType<unknown>>(
params?: GetPageConfigParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10PageConfig>>,
Awaited<ReturnType<typeof getPageConfig>>,
TError,
Awaited<ReturnType<typeof getApiV10PageConfig>>
Awaited<ReturnType<typeof getPageConfig>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10PageConfigInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10PageConfig>>>, TError = unknown>(
params?: GetApiV10PageConfigParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData>>, fetch?: RequestInit}
export function useGetPageConfigInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getPageConfig>>>, TError = ErrorType<unknown>>(
params?: GetPageConfigParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get hierarchical pageConfig
*/
export function useGetApiV10PageConfigInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getApiV10PageConfig>>>, TError = unknown>(
params?: GetApiV10PageConfigParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData>>, fetch?: RequestInit}
export function useGetPageConfigInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getPageConfig>>>, TError = ErrorType<unknown>>(
params?: GetPageConfigParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetApiV10PageConfigInfiniteQueryOptions(params,options)
const queryOptions = getGetPageConfigInfiniteQueryOptions(params,options)
const query = useInfiniteQuery(queryOptions, queryClient) as UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
......@@ -593,12 +573,12 @@ export function useGetApiV10PageConfigInfinite<TData = InfiniteData<Awaited<Retu
/**
* @summary Get hierarchical pageConfig
*/
export const prefetchGetApiV10PageConfigInfiniteQuery = async <TData = Awaited<ReturnType<typeof getApiV10PageConfig>>, TError = unknown>(
queryClient: QueryClient, params?: GetApiV10PageConfigParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData>>, fetch?: RequestInit}
export const prefetchGetPageConfigInfiniteQuery = async <TData = Awaited<ReturnType<typeof getPageConfig>>, TError = ErrorType<unknown>>(
queryClient: QueryClient, params?: GetPageConfigParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetApiV10PageConfigInfiniteQueryOptions(params,options)
const queryOptions = getGetPageConfigInfiniteQueryOptions(params,options)
await queryClient.prefetchInfiniteQuery(queryOptions);
......@@ -607,62 +587,62 @@ export const prefetchGetApiV10PageConfigInfiniteQuery = async <TData = Awaited<R
export const getGetApiV10PageConfigQueryOptions = <TData = Awaited<ReturnType<typeof getApiV10PageConfig>>, TError = unknown>(params?: GetApiV10PageConfigParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData>>, fetch?: RequestInit}
export const getGetPageConfigQueryOptions = <TData = Awaited<ReturnType<typeof getPageConfig>>, TError = ErrorType<unknown>>(params?: GetPageConfigParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, fetch: fetchOptions} = options ?? {};
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetApiV10PageConfigQueryKey(params);
const queryKey = queryOptions?.queryKey ?? getGetPageConfigQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getApiV10PageConfig>>> = ({ signal }) => getApiV10PageConfig(params, { signal, ...fetchOptions });
const queryFn: QueryFunction<Awaited<ReturnType<typeof getPageConfig>>> = ({ signal }) => getPageConfig(params, { signal, ...requestOptions });
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetApiV10PageConfigQueryResult = NonNullable<Awaited<ReturnType<typeof getApiV10PageConfig>>>
export type GetApiV10PageConfigQueryError = unknown
export type GetPageConfigQueryResult = NonNullable<Awaited<ReturnType<typeof getPageConfig>>>
export type GetPageConfigQueryError = ErrorType<unknown>
export function useGetApiV10PageConfig<TData = Awaited<ReturnType<typeof getApiV10PageConfig>>, TError = unknown>(
params: undefined | GetApiV10PageConfigParams, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData>> & Pick<
export function useGetPageConfig<TData = Awaited<ReturnType<typeof getPageConfig>>, TError = ErrorType<unknown>>(
params: undefined | GetPageConfigParams, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10PageConfig>>,
Awaited<ReturnType<typeof getPageConfig>>,
TError,
Awaited<ReturnType<typeof getApiV10PageConfig>>
Awaited<ReturnType<typeof getPageConfig>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10PageConfig<TData = Awaited<ReturnType<typeof getApiV10PageConfig>>, TError = unknown>(
params?: GetApiV10PageConfigParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData>> & Pick<
export function useGetPageConfig<TData = Awaited<ReturnType<typeof getPageConfig>>, TError = ErrorType<unknown>>(
params?: GetPageConfigParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getApiV10PageConfig>>,
Awaited<ReturnType<typeof getPageConfig>>,
TError,
Awaited<ReturnType<typeof getApiV10PageConfig>>
Awaited<ReturnType<typeof getPageConfig>>
> , 'initialData'
>, fetch?: RequestInit}
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetApiV10PageConfig<TData = Awaited<ReturnType<typeof getApiV10PageConfig>>, TError = unknown>(
params?: GetApiV10PageConfigParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData>>, fetch?: RequestInit}
export function useGetPageConfig<TData = Awaited<ReturnType<typeof getPageConfig>>, TError = ErrorType<unknown>>(
params?: GetPageConfigParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get hierarchical pageConfig
*/
export function useGetApiV10PageConfig<TData = Awaited<ReturnType<typeof getApiV10PageConfig>>, TError = unknown>(
params?: GetApiV10PageConfigParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData>>, fetch?: RequestInit}
export function useGetPageConfig<TData = Awaited<ReturnType<typeof getPageConfig>>, TError = ErrorType<unknown>>(
params?: GetPageConfigParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetApiV10PageConfigQueryOptions(params,options)
const queryOptions = getGetPageConfigQueryOptions(params,options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
......@@ -674,12 +654,12 @@ export function useGetApiV10PageConfig<TData = Awaited<ReturnType<typeof getApiV
/**
* @summary Get hierarchical pageConfig
*/
export const prefetchGetApiV10PageConfigQuery = async <TData = Awaited<ReturnType<typeof getApiV10PageConfig>>, TError = unknown>(
queryClient: QueryClient, params?: GetApiV10PageConfigParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getApiV10PageConfig>>, TError, TData>>, fetch?: RequestInit}
export const prefetchGetPageConfigQuery = async <TData = Awaited<ReturnType<typeof getPageConfig>>, TError = ErrorType<unknown>>(
queryClient: QueryClient, params?: GetPageConfigParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getPageConfig>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetApiV10PageConfigQueryOptions(params,options)
const queryOptions = getGetPageConfigQueryOptions(params,options)
await queryClient.prefetchQuery(queryOptions);
......@@ -692,65 +672,59 @@ export const prefetchGetApiV10PageConfigQuery = async <TData = Awaited<ReturnTyp
* Create a new pageConfig record. parent_id is required. level is computed from parent and must not be sent.
* @summary Create a pageConfig
*/
export type postApiV10PageConfigResponse200 = {
export type postPageConfigResponse200 = {
data: void
status: 200
}
export type postApiV10PageConfigResponseSuccess = (postApiV10PageConfigResponse200) & {
export type postPageConfigResponseSuccess = (postPageConfigResponse200) & {
headers: Headers;
};
;
export type postApiV10PageConfigResponse = (postApiV10PageConfigResponseSuccess)
export type postPageConfigResponse = (postPageConfigResponseSuccess)
export const getPostApiV10PageConfigUrl = () => {
export const getPostPageConfigUrl = () => {
return `/api/v1.0/pageConfig`
return `/pageConfig`
}
export const postApiV10PageConfig = async (postApiV10PageConfigBody: PostApiV10PageConfigBody, options?: RequestInit): Promise<postApiV10PageConfigResponse> => {
export const postPageConfig = async (postPageConfigBody: PostPageConfigBody, options?: RequestInit): Promise<postPageConfigResponse> => {
const res = await fetch(getPostApiV10PageConfigUrl(),
return useCustomClient<postPageConfigResponse>(getPostPageConfigUrl(),
{
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(
postApiV10PageConfigBody,)
postPageConfigBody,)
}
)
const body = [204, 205, 304].includes(res.status) ? null : await res.text();
const data: postApiV10PageConfigResponse['data'] = body ? JSON.parse(body) : {}
return { data, status: res.status, headers: res.headers } as postApiV10PageConfigResponse
}
);}
export const getPostApiV10PageConfigMutationOptions = <TError = unknown,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postApiV10PageConfig>>, TError,{data: PostApiV10PageConfigBody}, TContext>, fetch?: RequestInit}
): UseMutationOptions<Awaited<ReturnType<typeof postApiV10PageConfig>>, TError,{data: PostApiV10PageConfigBody}, TContext> => {
export const getPostPageConfigMutationOptions = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postPageConfig>>, TError,{data: BodyType<PostPageConfigBody>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof postPageConfig>>, TError,{data: BodyType<PostPageConfigBody>}, TContext> => {
const mutationKey = ['postApiV10PageConfig'];
const {mutation: mutationOptions, fetch: fetchOptions} = options ?
const mutationKey = ['postPageConfig'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, fetch: undefined};
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof postApiV10PageConfig>>, {data: PostApiV10PageConfigBody}> = (props) => {
const mutationFn: MutationFunction<Awaited<ReturnType<typeof postPageConfig>>, {data: BodyType<PostPageConfigBody>}> = (props) => {
const {data} = props ?? {};
return postApiV10PageConfig(data,fetchOptions)
return postPageConfig(data,requestOptions)
}
......@@ -758,23 +732,23 @@ const {mutation: mutationOptions, fetch: fetchOptions} = options ?
return { mutationFn, ...mutationOptions }}
export type PostApiV10PageConfigMutationResult = NonNullable<Awaited<ReturnType<typeof postApiV10PageConfig>>>
export type PostApiV10PageConfigMutationBody = PostApiV10PageConfigBody
export type PostApiV10PageConfigMutationError = unknown
export type PostPageConfigMutationResult = NonNullable<Awaited<ReturnType<typeof postPageConfig>>>
export type PostPageConfigMutationBody = BodyType<PostPageConfigBody>
export type PostPageConfigMutationError = ErrorType<unknown>
/**
* @summary Create a pageConfig
*/
export const usePostApiV10PageConfig = <TError = unknown,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postApiV10PageConfig>>, TError,{data: PostApiV10PageConfigBody}, TContext>, fetch?: RequestInit}
export const usePostPageConfig = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postPageConfig>>, TError,{data: BodyType<PostPageConfigBody>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof postApiV10PageConfig>>,
Awaited<ReturnType<typeof postPageConfig>>,
TError,
{data: PostApiV10PageConfigBody},
{data: BodyType<PostPageConfigBody>},
TContext
> => {
const mutationOptions = getPostApiV10PageConfigMutationOptions(options);
const mutationOptions = getPostPageConfigMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import {
useInfiniteQuery,
useMutation,
useQuery
} from '@tanstack/react-query';
import type {
DataTag,
DefinedInitialDataOptions,
DefinedUseInfiniteQueryResult,
DefinedUseQueryResult,
InfiniteData,
MutationFunction,
QueryClient,
QueryFunction,
QueryKey,
UndefinedInitialDataOptions,
UseInfiniteQueryOptions,
UseInfiniteQueryResult,
UseMutationOptions,
UseMutationResult,
UseQueryOptions,
UseQueryResult
} from '@tanstack/react-query';
import type {
GetVideoId200,
GetVideoParams,
PatchVideoId200,
PostVideo200,
ResponseGetAllData,
VideoMutate
} from '../models';
import { useCustomClient } from '../mutator/custom-client';
import type { ErrorType , BodyType } from '../mutator/custom-client';
type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
/**
* Retrieve a specific video by its ID
* @summary Get a video by ID
*/
export type getVideoIdResponse200 = {
data: GetVideoId200
status: 200
}
export type getVideoIdResponseSuccess = (getVideoIdResponse200) & {
headers: Headers;
};
;
export type getVideoIdResponse = (getVideoIdResponseSuccess)
export const getGetVideoIdUrl = (id: string,) => {
return `/video/${id}`
}
export const getVideoId = async (id: string, options?: RequestInit): Promise<getVideoIdResponse> => {
return useCustomClient<getVideoIdResponse>(getGetVideoIdUrl(id),
{
...options,
method: 'GET'
}
);}
export const getGetVideoIdInfiniteQueryKey = (id?: string,) => {
return [
'infinite', `/video/${id}`
] as const;
}
export const getGetVideoIdQueryKey = (id?: string,) => {
return [
`/video/${id}`
] as const;
}
export const getGetVideoIdInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getVideoId>>>, TError = ErrorType<unknown>>(id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetVideoIdInfiniteQueryKey(id);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getVideoId>>> = ({ signal }) => getVideoId(id, { signal, ...requestOptions });
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetVideoIdInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getVideoId>>>
export type GetVideoIdInfiniteQueryError = ErrorType<unknown>
export function useGetVideoIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getVideoId>>>, TError = ErrorType<unknown>>(
id: string, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getVideoId>>,
TError,
Awaited<ReturnType<typeof getVideoId>>
> , 'initialData'
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetVideoIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getVideoId>>>, TError = ErrorType<unknown>>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getVideoId>>,
TError,
Awaited<ReturnType<typeof getVideoId>>
> , 'initialData'
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetVideoIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getVideoId>>>, TError = ErrorType<unknown>>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get a video by ID
*/
export function useGetVideoIdInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getVideoId>>>, TError = ErrorType<unknown>>(
id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetVideoIdInfiniteQueryOptions(id,options)
const query = useInfiniteQuery(queryOptions, queryClient) as UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary Get a video by ID
*/
export const prefetchGetVideoIdInfiniteQuery = async <TData = Awaited<ReturnType<typeof getVideoId>>, TError = ErrorType<unknown>>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetVideoIdInfiniteQueryOptions(id,options)
await queryClient.prefetchInfiniteQuery(queryOptions);
return queryClient;
}
export const getGetVideoIdQueryOptions = <TData = Awaited<ReturnType<typeof getVideoId>>, TError = ErrorType<unknown>>(id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetVideoIdQueryKey(id);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getVideoId>>> = ({ signal }) => getVideoId(id, { signal, ...requestOptions });
return { queryKey, queryFn, enabled: !!(id), retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetVideoIdQueryResult = NonNullable<Awaited<ReturnType<typeof getVideoId>>>
export type GetVideoIdQueryError = ErrorType<unknown>
export function useGetVideoId<TData = Awaited<ReturnType<typeof getVideoId>>, TError = ErrorType<unknown>>(
id: string, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getVideoId>>,
TError,
Awaited<ReturnType<typeof getVideoId>>
> , 'initialData'
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetVideoId<TData = Awaited<ReturnType<typeof getVideoId>>, TError = ErrorType<unknown>>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getVideoId>>,
TError,
Awaited<ReturnType<typeof getVideoId>>
> , 'initialData'
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetVideoId<TData = Awaited<ReturnType<typeof getVideoId>>, TError = ErrorType<unknown>>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get a video by ID
*/
export function useGetVideoId<TData = Awaited<ReturnType<typeof getVideoId>>, TError = ErrorType<unknown>>(
id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetVideoIdQueryOptions(id,options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary Get a video by ID
*/
export const prefetchGetVideoIdQuery = async <TData = Awaited<ReturnType<typeof getVideoId>>, TError = ErrorType<unknown>>(
queryClient: QueryClient, id: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getVideoId>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetVideoIdQueryOptions(id,options)
await queryClient.prefetchQuery(queryOptions);
return queryClient;
}
/**
* Update an existing video record
* @summary Update a video
*/
export type patchVideoIdResponse200 = {
data: PatchVideoId200
status: 200
}
export type patchVideoIdResponseSuccess = (patchVideoIdResponse200) & {
headers: Headers;
};
;
export type patchVideoIdResponse = (patchVideoIdResponseSuccess)
export const getPatchVideoIdUrl = (id: string,) => {
return `/video/${id}`
}
export const patchVideoId = async (id: string,
videoMutate: VideoMutate, options?: RequestInit): Promise<patchVideoIdResponse> => {
return useCustomClient<patchVideoIdResponse>(getPatchVideoIdUrl(id),
{
...options,
method: 'PATCH',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(
videoMutate,)
}
);}
export const getPatchVideoIdMutationOptions = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof patchVideoId>>, TError,{id: string;data: BodyType<VideoMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof patchVideoId>>, TError,{id: string;data: BodyType<VideoMutate>}, TContext> => {
const mutationKey = ['patchVideoId'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof patchVideoId>>, {id: string;data: BodyType<VideoMutate>}> = (props) => {
const {id,data} = props ?? {};
return patchVideoId(id,data,requestOptions)
}
return { mutationFn, ...mutationOptions }}
export type PatchVideoIdMutationResult = NonNullable<Awaited<ReturnType<typeof patchVideoId>>>
export type PatchVideoIdMutationBody = BodyType<VideoMutate>
export type PatchVideoIdMutationError = ErrorType<unknown>
/**
* @summary Update a video
*/
export const usePatchVideoId = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof patchVideoId>>, TError,{id: string;data: BodyType<VideoMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof patchVideoId>>,
TError,
{id: string;data: BodyType<VideoMutate>},
TContext
> => {
const mutationOptions = getPatchVideoIdMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
/**
* Replace an existing video record
* @summary Replace a video
*/
export type putVideoIdResponse200 = {
data: void
status: 200
}
export type putVideoIdResponseSuccess = (putVideoIdResponse200) & {
headers: Headers;
};
;
export type putVideoIdResponse = (putVideoIdResponseSuccess)
export const getPutVideoIdUrl = (id: string,) => {
return `/video/${id}`
}
export const putVideoId = async (id: string,
videoMutate: VideoMutate, options?: RequestInit): Promise<putVideoIdResponse> => {
return useCustomClient<putVideoIdResponse>(getPutVideoIdUrl(id),
{
...options,
method: 'PUT',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(
videoMutate,)
}
);}
export const getPutVideoIdMutationOptions = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putVideoId>>, TError,{id: string;data: BodyType<VideoMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof putVideoId>>, TError,{id: string;data: BodyType<VideoMutate>}, TContext> => {
const mutationKey = ['putVideoId'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof putVideoId>>, {id: string;data: BodyType<VideoMutate>}> = (props) => {
const {id,data} = props ?? {};
return putVideoId(id,data,requestOptions)
}
return { mutationFn, ...mutationOptions }}
export type PutVideoIdMutationResult = NonNullable<Awaited<ReturnType<typeof putVideoId>>>
export type PutVideoIdMutationBody = BodyType<VideoMutate>
export type PutVideoIdMutationError = ErrorType<unknown>
/**
* @summary Replace a video
*/
export const usePutVideoId = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof putVideoId>>, TError,{id: string;data: BodyType<VideoMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof putVideoId>>,
TError,
{id: string;data: BodyType<VideoMutate>},
TContext
> => {
const mutationOptions = getPutVideoIdMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
/**
* Delete a video record
* @summary Delete a video
*/
export type deleteVideoIdResponse200 = {
data: void
status: 200
}
export type deleteVideoIdResponseSuccess = (deleteVideoIdResponse200) & {
headers: Headers;
};
;
export type deleteVideoIdResponse = (deleteVideoIdResponseSuccess)
export const getDeleteVideoIdUrl = (id: string,) => {
return `/video/${id}`
}
export const deleteVideoId = async (id: string, options?: RequestInit): Promise<deleteVideoIdResponse> => {
return useCustomClient<deleteVideoIdResponse>(getDeleteVideoIdUrl(id),
{
...options,
method: 'DELETE'
}
);}
export const getDeleteVideoIdMutationOptions = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteVideoId>>, TError,{id: string}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof deleteVideoId>>, TError,{id: string}, TContext> => {
const mutationKey = ['deleteVideoId'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof deleteVideoId>>, {id: string}> = (props) => {
const {id} = props ?? {};
return deleteVideoId(id,requestOptions)
}
return { mutationFn, ...mutationOptions }}
export type DeleteVideoIdMutationResult = NonNullable<Awaited<ReturnType<typeof deleteVideoId>>>
export type DeleteVideoIdMutationError = ErrorType<unknown>
/**
* @summary Delete a video
*/
export const useDeleteVideoId = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteVideoId>>, TError,{id: string}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof deleteVideoId>>,
TError,
{id: string},
TContext
> => {
const mutationOptions = getDeleteVideoIdMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
/**
* Retrieve a list of videos with pagination, filtering and sorting
* @summary Get all videos
*/
export type getVideoResponse200 = {
data: ResponseGetAllData
status: 200
}
export type getVideoResponseSuccess = (getVideoResponse200) & {
headers: Headers;
};
;
export type getVideoResponse = (getVideoResponseSuccess)
export const getGetVideoUrl = (params?: GetVideoParams,) => {
const normalizedParams = new URLSearchParams();
Object.entries(params || {}).forEach(([key, value]) => {
if (value !== undefined) {
normalizedParams.append(key, value === null ? 'null' : value.toString())
}
});
const stringifiedParams = normalizedParams.toString();
return stringifiedParams.length > 0 ? `/video?${stringifiedParams}` : `/video`
}
export const getVideo = async (params?: GetVideoParams, options?: RequestInit): Promise<getVideoResponse> => {
return useCustomClient<getVideoResponse>(getGetVideoUrl(params),
{
...options,
method: 'GET'
}
);}
export const getGetVideoInfiniteQueryKey = (params?: GetVideoParams,) => {
return [
'infinite', `/video`, ...(params ? [params]: [])
] as const;
}
export const getGetVideoQueryKey = (params?: GetVideoParams,) => {
return [
`/video`, ...(params ? [params]: [])
] as const;
}
export const getGetVideoInfiniteQueryOptions = <TData = InfiniteData<Awaited<ReturnType<typeof getVideo>>>, TError = ErrorType<unknown>>(params?: GetVideoParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetVideoInfiniteQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getVideo>>> = ({ signal }) => getVideo(params, { signal, ...requestOptions });
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetVideoInfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof getVideo>>>
export type GetVideoInfiniteQueryError = ErrorType<unknown>
export function useGetVideoInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getVideo>>>, TError = ErrorType<unknown>>(
params: undefined | GetVideoParams, options: { query:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getVideo>>,
TError,
Awaited<ReturnType<typeof getVideo>>
> , 'initialData'
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetVideoInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getVideo>>>, TError = ErrorType<unknown>>(
params?: GetVideoParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getVideo>>,
TError,
Awaited<ReturnType<typeof getVideo>>
> , 'initialData'
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetVideoInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getVideo>>>, TError = ErrorType<unknown>>(
params?: GetVideoParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get all videos
*/
export function useGetVideoInfinite<TData = InfiniteData<Awaited<ReturnType<typeof getVideo>>>, TError = ErrorType<unknown>>(
params?: GetVideoParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetVideoInfiniteQueryOptions(params,options)
const query = useInfiniteQuery(queryOptions, queryClient) as UseInfiniteQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary Get all videos
*/
export const prefetchGetVideoInfiniteQuery = async <TData = Awaited<ReturnType<typeof getVideo>>, TError = ErrorType<unknown>>(
queryClient: QueryClient, params?: GetVideoParams, options?: { query?:Partial<UseInfiniteQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetVideoInfiniteQueryOptions(params,options)
await queryClient.prefetchInfiniteQuery(queryOptions);
return queryClient;
}
export const getGetVideoQueryOptions = <TData = Awaited<ReturnType<typeof getVideo>>, TError = ErrorType<unknown>>(params?: GetVideoParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
) => {
const {query: queryOptions, request: requestOptions} = options ?? {};
const queryKey = queryOptions?.queryKey ?? getGetVideoQueryKey(params);
const queryFn: QueryFunction<Awaited<ReturnType<typeof getVideo>>> = ({ signal }) => getVideo(params, { signal, ...requestOptions });
return { queryKey, queryFn, retry: 3, retryDelay: 1000, ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData> & { queryKey: DataTag<QueryKey, TData, TError> }
}
export type GetVideoQueryResult = NonNullable<Awaited<ReturnType<typeof getVideo>>>
export type GetVideoQueryError = ErrorType<unknown>
export function useGetVideo<TData = Awaited<ReturnType<typeof getVideo>>, TError = ErrorType<unknown>>(
params: undefined | GetVideoParams, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData>> & Pick<
DefinedInitialDataOptions<
Awaited<ReturnType<typeof getVideo>>,
TError,
Awaited<ReturnType<typeof getVideo>>
> , 'initialData'
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetVideo<TData = Awaited<ReturnType<typeof getVideo>>, TError = ErrorType<unknown>>(
params?: GetVideoParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData>> & Pick<
UndefinedInitialDataOptions<
Awaited<ReturnType<typeof getVideo>>,
TError,
Awaited<ReturnType<typeof getVideo>>
> , 'initialData'
>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
export function useGetVideo<TData = Awaited<ReturnType<typeof getVideo>>, TError = ErrorType<unknown>>(
params?: GetVideoParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> }
/**
* @summary Get all videos
*/
export function useGetVideo<TData = Awaited<ReturnType<typeof getVideo>>, TError = ErrorType<unknown>>(
params?: GetVideoParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient
): UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> } {
const queryOptions = getGetVideoQueryOptions(params,options)
const query = useQuery(queryOptions, queryClient) as UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData, TError> };
query.queryKey = queryOptions.queryKey ;
return query;
}
/**
* @summary Get all videos
*/
export const prefetchGetVideoQuery = async <TData = Awaited<ReturnType<typeof getVideo>>, TError = ErrorType<unknown>>(
queryClient: QueryClient, params?: GetVideoParams, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getVideo>>, TError, TData>>, request?: SecondParameter<typeof useCustomClient>}
): Promise<QueryClient> => {
const queryOptions = getGetVideoQueryOptions(params,options)
await queryClient.prefetchQuery(queryOptions);
return queryClient;
}
/**
* Create a new video record
* @summary Create a video
*/
export type postVideoResponse200 = {
data: PostVideo200
status: 200
}
export type postVideoResponseSuccess = (postVideoResponse200) & {
headers: Headers;
};
;
export type postVideoResponse = (postVideoResponseSuccess)
export const getPostVideoUrl = () => {
return `/video`
}
export const postVideo = async (videoMutate: VideoMutate, options?: RequestInit): Promise<postVideoResponse> => {
return useCustomClient<postVideoResponse>(getPostVideoUrl(),
{
...options,
method: 'POST',
headers: { 'Content-Type': 'application/json', ...options?.headers },
body: JSON.stringify(
videoMutate,)
}
);}
export const getPostVideoMutationOptions = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postVideo>>, TError,{data: BodyType<VideoMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
): UseMutationOptions<Awaited<ReturnType<typeof postVideo>>, TError,{data: BodyType<VideoMutate>}, TContext> => {
const mutationKey = ['postVideo'];
const {mutation: mutationOptions, request: requestOptions} = options ?
options.mutation && 'mutationKey' in options.mutation && options.mutation.mutationKey ?
options
: {...options, mutation: {...options.mutation, mutationKey}}
: {mutation: { mutationKey, }, request: undefined};
const mutationFn: MutationFunction<Awaited<ReturnType<typeof postVideo>>, {data: BodyType<VideoMutate>}> = (props) => {
const {data} = props ?? {};
return postVideo(data,requestOptions)
}
return { mutationFn, ...mutationOptions }}
export type PostVideoMutationResult = NonNullable<Awaited<ReturnType<typeof postVideo>>>
export type PostVideoMutationBody = BodyType<VideoMutate>
export type PostVideoMutationError = ErrorType<unknown>
/**
* @summary Create a video
*/
export const usePostVideo = <TError = ErrorType<unknown>,
TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof postVideo>>, TError,{data: BodyType<VideoMutate>}, TContext>, request?: SecondParameter<typeof useCustomClient>}
, queryClient?: QueryClient): UseMutationResult<
Awaited<ReturnType<typeof postVideo>>,
TError,
{data: BodyType<VideoMutate>},
TContext
> => {
const mutationOptions = getPostVideoMutationOptions(options);
return useMutation(mutationOptions, queryClient);
}
\ No newline at end of file
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { BadRequestResponseError } from './badRequestResponseError';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { BadRequestResponseErrorMessage } from './badRequestResponseErrorMessage';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { Category } from './category';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { FiltersParameter } from './filtersParameter';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { Contact } from './contact';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { FiltersParameter } from './filtersParameter';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { FiltersParameter } from './filtersParameter';
import type { SortFieldParameter } from './sortFieldParameter';
import type { SortOrderParameter } from './sortOrderParameter';
import type { PageParameter } from './pageParameter';
import type { PageSizeParameter } from './pageSizeParameter';
export type GetNewsletterSubscriptionParams = {
/**
* filter, visit https://www.npmjs.com/package/sequelize-api-paginate for syntax
*/
filters?: FiltersParameter;
/**
* sortField, visit https://www.npmjs.com/package/sequelize-api-paginate for syntax
*/
sortField?: SortFieldParameter;
/**
* sort order, visit https://www.npmjs.com/package/sequelize-api-paginate for syntax
*/
sortOrder?: SortOrderParameter;
/**
* page, visit https://www.npmjs.com/package/sequelize-api-paginate for syntax
* @minimum 1
*/
page?: PageParameter;
/**
* pageSize, visit https://www.npmjs.com/package/sequelize-api-paginate for syntax
* @minimum 1
*/
pageSize?: PageSizeParameter;
};
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
import type { GetVideoId200AllOf } from './getVideoId200AllOf';
export type GetVideoId200 = ApiResponse & GetVideoId200AllOf;
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { Video } from './video';
export type GetVideoId200AllOf = {
responseData?: Video;
};
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { FiltersParameter } from './filtersParameter';
import type { SortFieldParameter } from './sortFieldParameter';
import type { SortOrderParameter } from './sortOrderParameter';
import type { PageParameter } from './pageParameter';
import type { PageSizeParameter } from './pageSizeParameter';
export type GetVideoParams = {
/**
* filter, visit https://www.npmjs.com/package/sequelize-api-paginate for syntax
*/
filters?: FiltersParameter;
/**
* sortField, visit https://www.npmjs.com/package/sequelize-api-paginate for syntax
*/
sortField?: SortFieldParameter;
/**
* sort order, visit https://www.npmjs.com/package/sequelize-api-paginate for syntax
*/
sortOrder?: SortOrderParameter;
/**
* page, visit https://www.npmjs.com/package/sequelize-api-paginate for syntax
* @minimum 1
*/
page?: PageParameter;
/**
* pageSize, visit https://www.npmjs.com/package/sequelize-api-paginate for syntax
* @minimum 1
*/
pageSize?: PageSizeParameter;
};
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......@@ -114,6 +114,7 @@ export * from './getMembershipFeePrintParams';
export * from './getNewsAdminParams';
export * from './getNewsPageConfigGetHierarchicalParams';
export * from './getNewsParams';
export * from './getNewsletterSubscriptionParams';
export * from './getNotificationsParams';
export * from './getOrderGetMyOrdersParams';
export * from './getOrderParams';
......@@ -150,6 +151,9 @@ export * from './getUsersPartakerParams';
export * from './getUsersPrintParams';
export * from './getUsersValidationParams';
export * from './getUsersWithoutMembershipFeeByYearParams';
export * from './getVideoId200';
export * from './getVideoId200AllOf';
export * from './getVideoParams';
export * from './loginRequest';
export * from './loginRequestDeviceInfo';
export * from './loginResponse';
......@@ -178,6 +182,9 @@ export * from './migrationMappingMetadata';
export * from './migrationMappingMutate';
export * from './migrationMappingMutateMetadata';
export * from './news';
export * from './newsletterSubscription';
export * from './newsletterSubscriptionMutate';
export * from './newsletterSubscriptionUpdate';
export * from './notification';
export * from './obj2Body';
export * from './obj3Body';
......@@ -212,6 +219,10 @@ export * from './pageConfigTag';
export * from './pageConfigTagMutate';
export * from './pageParameter';
export * from './pageSizeParameter';
export * from './patchNewsletterSubscriptionId200';
export * from './patchNewsletterSubscriptionId200AllOf';
export * from './patchVideoId200';
export * from './patchVideoId200AllOf';
export * from './permision';
export * from './permisionFunction';
export * from './permisionFunctionBody';
......@@ -249,6 +260,8 @@ export * from './postMembershipFeeSendUpdateReminderBodyLanguage';
export * from './postMembershipFeeSendUpdateReminderBodyOrganizationsItem';
export * from './postMutate';
export * from './postMutateContentStructure';
export * from './postNewsletterSubscription200';
export * from './postNewsletterSubscription200AllOf';
export * from './postOrganizationsAddMembershipFeesBody';
export * from './postOrganizationsAddMembershipFeesBodyFeesItem';
export * from './postOrganizationsCheckAccountsBody';
......@@ -263,6 +276,8 @@ export * from './postUsersAdminParams';
export * from './postUsersFavoriteAddBody';
export * from './postUsersFavoriteAddParams';
export * from './postValidatorOrgCodeBody';
export * from './postVideo200';
export * from './postVideo200AllOf';
export * from './putApiV10CategoryId200';
export * from './putApiV10CategoryId200AllOf';
export * from './putApiV10ContactId200';
......@@ -391,4 +406,6 @@ export * from './userUpdateGender';
export * from './userUpdateType';
export * from './userValidation';
export * from './userVerify';
export * from './video';
export * from './videoMutate';
export * from './webConfig';
\ No newline at end of file
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { LoginRequestDeviceInfo } from './loginRequestDeviceInfo';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { MemberImportWarningItem } from './memberImportWarningItem';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
export interface NewsletterSubscription {
id: string;
email: string;
is_seen: boolean;
/** @nullable */
seen_at?: string | null;
created_at: string;
updated_at: string;
}
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
export interface NewsletterSubscriptionMutate {
email: string;
}
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
export interface NewsletterSubscriptionUpdate {
is_seen: boolean;
}
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
import type { PatchNewsletterSubscriptionId200AllOf } from './patchNewsletterSubscriptionId200AllOf';
export type PatchNewsletterSubscriptionId200 = ApiResponse & PatchNewsletterSubscriptionId200AllOf;
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { NewsletterSubscription } from './newsletterSubscription';
export type PatchNewsletterSubscriptionId200AllOf = {
responseData?: NewsletterSubscription;
};
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
import type { PatchVideoId200AllOf } from './patchVideoId200AllOf';
export type PatchVideoId200 = ApiResponse & PatchVideoId200AllOf;
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { Video } from './video';
export type PatchVideoId200AllOf = {
responseData?: Video;
};
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { PermissionCreate } from './permissionCreate';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { PermissionCreate } from './permissionCreate';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { Category } from './category';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { Contact } from './contact';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
import type { PostNewsletterSubscription200AllOf } from './postNewsletterSubscription200AllOf';
export type PostNewsletterSubscription200 = ApiResponse & PostNewsletterSubscription200AllOf;
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { NewsletterSubscription } from './newsletterSubscription';
export type PostNewsletterSubscription200AllOf = {
responseData?: NewsletterSubscription;
};
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
import type { PostVideo200AllOf } from './postVideo200AllOf';
export type PostVideo200 = ApiResponse & PostVideo200AllOf;
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { Video } from './video';
export type PostVideo200AllOf = {
responseData?: Video;
};
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { Category } from './category';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ApiResponse } from './apiResponse';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { Contact } from './contact';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ResponseResponseData } from './responseResponseData';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { Response } from './response';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ResponseGetAllDataAllOfResponseData } from './responseGetAllDataAllOfResponseData';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { ResponseGetAllDataAllOfResponseDataRowsItem } from './responseGetAllDataAllOfResponseDataRowsItem';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { RoleCreate } from './roleCreate';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { TermPositionRequestItem } from './termPositionRequestItem';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { TermMemberAvatarProperty } from './termMemberAvatarProperty';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { TermMemberAvatar } from './termMemberAvatar';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { TermMember } from './termMember';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { TermPositionResponse } from './termPositionResponse';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { TermPositionRequestItem } from './termPositionRequestItem';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { UnauthorizedResponseError } from './unauthorizedResponseError';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
import type { UnauthorizedResponseErrorMessage } from './unauthorizedResponseErrorMessage';
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* VietProDev CMS Backend API
* Generated API documentation
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
......
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
export interface Video {
id: string;
name: string;
url: string;
created_at: string;
/** @nullable */
created_by?: string | null;
updated_at: string;
/** @nullable */
updated_by?: string | null;
}
/**
* Generated by orval v8.0.0-rc.0 🍺
* Do not edit manually.
* Backend Template
* Coded by Meu TEAM
* OpenAPI spec version: 1.0.0
*/
export interface VideoMutate {
name: string;
url: string;
}
'use client';
"use client";
import { useQuery } from "@tanstack/react-query";
import ImageNext from "@/components/shared/image-next";
import partnerImages from "@/constants/partnerImages";
import { ChevronRight, Play } from "lucide-react";
import Link from "next/link";
const videos = [
{
embedSrc: "https://www.youtube.com/embed/J0Iz0iGuAXY",
title: "VCCI-HCM 2025 IN REVIEW (ENGLISH VERSION)",
thumbnail:
"https://img.youtube.com/vi/J0Iz0iGuAXY/hqdefault.jpg",
},
{
embedSrc: "https://www.youtube.com/embed/_OnnGWv2ehM",
title: "Hội nghị Hội viên VCCI - Gala Mừng Xuân 2026",
thumbnail:
"https://img.youtube.com/vi/_OnnGWv2ehM/hqdefault.jpg",
},
];
import { fetchClientVideos } from "@/lib/api/videos";
function VideoAndPartners() {
const videosQuery = useQuery({
queryKey: ["home-videos"],
queryFn: () => fetchClientVideos({ page: 1, pageSize: 2 }),
staleTime: 60 * 1000,
});
const videos = videosQuery.data?.rows ?? [];
return (
<section className="flex flex-col gap-6 pb-10 xl:flex-row xl:items-stretch">
<div className="flex-1">
......@@ -41,10 +36,18 @@ function VideoAndPartners() {
</div>
<div className="grid gap-4 md:grid-cols-2">
{videos.map((video) => (
{videosQuery.isLoading ? (
Array.from({ length: 2 }).map((_, index) => (
<div
key={`video-loading-${index}`}
className="h-[202px] animate-pulse rounded-[16px] bg-[#edf1f7]"
/>
))
) : videos.length ? (
videos.map((video) => (
<a
key={video.embedSrc}
href={video.embedSrc.replace("/embed/", "/watch?v=")}
key={video.id}
href={video.watchUrl}
target="_blank"
rel="noreferrer"
className="overflow-hidden rounded-[16px] border border-[#e5ebf4] bg-white shadow-[0_10px_22px_rgba(31,59,124,0.08)] transition-all hover:-translate-y-0.5 hover:shadow-[0_16px_30px_rgba(31,59,124,0.12)]"
......@@ -52,7 +55,7 @@ function VideoAndPartners() {
<div className="group relative aspect-[1.95/1] overflow-hidden">
<ImageNext
src={video.thumbnail}
alt={video.title}
alt={video.name}
width={640}
height={440}
className="h-full w-full object-cover transition-transform duration-500 group-hover:scale-[1.03]"
......@@ -67,11 +70,16 @@ function VideoAndPartners() {
<div className="px-4 py-2.5">
<p className="line-clamp-2 text-[14px] font-semibold leading-[1.32] text-[#264798] md:text-[15px]">
{video.title}
{video.name}
</p>
</div>
</a>
))}
))
) : (
<div className="rounded-[16px] border border-[#e5ebf4] bg-white px-5 py-10 text-center text-sm text-gray-500 md:col-span-2">
Chưa có video nào.
</div>
)}
</div>
</div>
......
......@@ -280,30 +280,50 @@ function createCategoryPostsQuery(categoryId: string, pageSize: string) {
}
async function fetchHomePosts() {
const query = new URLSearchParams({
const categoryRows = await fetchHomeCategoryRows().catch(() => []);
const trainingCategoryId = findCategoryIdByAliases(
categoryRows,
HOME_CATEGORY_ALIASES.daoTao,
);
const businessCategoryId = findCategoryIdByAliases(
categoryRows,
HOME_CATEGORY_ALIASES.coHoiKinhDoanh,
);
const memberConnectionCategoryId = findCategoryIdByAliases(
categoryRows,
HOME_CATEGORY_ALIASES.ketNoiHoiVien,
);
const featuredQuery = new URLSearchParams({
page: "1",
pageSize: "200",
sortField: "created_at",
pageSize: "10",
sortField: "release_at",
sortOrder: "desc",
filters: [
"is_featured==true",
"is_hidden==false",
"is_active==true",
"status==published",
"type==news",
].join(","),
});
const tinVcciQuery = createCategoryPostsQuery(HOME_CATEGORY_IDS.tinVcci, "6");
const tinKinhTeQuery = createCategoryPostsQuery(HOME_CATEGORY_IDS.tinKinhTe, "6");
const chuyenDeQuery = createCategoryPostsQuery(HOME_CATEGORY_IDS.chuyenDe, "6");
const eventQuery = createCategoryPostsQuery(HOME_CATEGORY_IDS.suKien, "5");
const policyQuery = createCategoryPostsQuery(HOME_CATEGORY_IDS.chinhSachPhapLuat, "6");
const quickLinksQuery = createCategoryPostsQuery(HOME_CATEGORY_IDS.lienKetNhanh, "6");
const categoryRows = await fetchHomeCategoryRows().catch(() => []);
const trainingCategoryId = findCategoryIdByAliases(
categoryRows,
HOME_CATEGORY_ALIASES.daoTao,
);
const trainingQuery = trainingCategoryId
? createCategoryPostsQuery(String(trainingCategoryId), "20")
? createCategoryPostsQuery(String(trainingCategoryId), "10")
: null;
const businessQuery = businessCategoryId
? createCategoryPostsQuery(String(businessCategoryId), "10")
: null;
const memberConnectionQuery = memberConnectionCategoryId
? createCategoryPostsQuery(String(memberConnectionCategoryId), "10")
: null;
const [
homeRows,
featuredRows,
tinVcciRows,
tinKinhTeRows,
chuyenDeRows,
......@@ -311,8 +331,10 @@ async function fetchHomePosts() {
eventRows,
quickLinkRows,
trainingRows,
businessRows,
memberConnectionRows,
] = await Promise.all([
fetchHomePostRows(`/post?${query.toString()}`),
fetchHomePostRows(`/post?${featuredQuery.toString()}`),
fetchHomePostRows(`/post?${tinVcciQuery.toString()}`),
fetchHomePostRows(`/post?${tinKinhTeQuery.toString()}`),
fetchHomePostRows(`/post?${chuyenDeQuery.toString()}`),
......@@ -320,9 +342,12 @@ async function fetchHomePosts() {
fetchHomePostRows(`/post?${eventQuery.toString()}`),
fetchHomePostRows(`/post?${quickLinksQuery.toString()}`),
trainingQuery ? fetchHomePostRows(`/post?${trainingQuery.toString()}`) : [],
businessQuery ? fetchHomePostRows(`/post?${businessQuery.toString()}`) : [],
memberConnectionQuery ? fetchHomePostRows(`/post?${memberConnectionQuery.toString()}`) : [],
]);
const rows = [
...featuredRows,
...tinVcciRows,
...tinKinhTeRows,
...chuyenDeRows,
......@@ -330,7 +355,8 @@ async function fetchHomePosts() {
...eventRows,
...trainingRows,
...quickLinkRows,
...homeRows,
...businessRows,
...memberConnectionRows,
];
return rows
......
'use client';
import { useEffect, useState } from "react";
import { notFound, useParams, usePathname, useRouter, useSearchParams } from "next/navigation";
import { useParams, usePathname, useRouter, useSearchParams } from "next/navigation";
import { useGetEvents } from "@/api/endpoints/event";
import { EventApiResponse } from "@/api/types/event";
......@@ -53,7 +53,7 @@ export default function EventPage() {
});
const { data: events, isLoading: eventsLoading } = useGetEvents<EventApiResponse>({
filters: `name@=${submitSearch ? `title@=${submitSearch}` : ""}`,
filters: submitSearch.trim() ? `name@=${submitSearch.trim()}` : undefined,
pageSize: String(pageSize),
currentPage: String(page),
});
......
"use client";
import React, { useRef, useState } from "react";
import React, { useState } from "react";
import {
Facebook,
Linkedin,
......@@ -8,11 +8,12 @@ import {
MapPin,
Phone,
Printer,
SendHorizonal,
SendHorizontal,
Twitter,
Youtube,
} from "lucide-react";
import Link from "next/link";
import { subscribeNewsletterEmail } from "@/lib/api/newsletter-subscriptions";
const socialLinks = [
{ icon: <Facebook className="h-5 w-5" />, link: "https://www.facebook.com/VCCIHCMC/" },
......@@ -31,18 +32,53 @@ const quickLinks = [
{ label: "Xúc tiến Thương mại", href: "/xuc-tien-thuong-mai/co-hoi/" },
];
const isValidEmail = (value: string) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
function Footer() {
const emailRef = useRef<HTMLInputElement>(null);
const checkBoxRef = useRef<HTMLInputElement>(null);
const [emailError, setEmailError] = useState(false);
const [email, setEmail] = useState("");
const [accepted, setAccepted] = useState(false);
const [emailError, setEmailError] = useState("");
const [checkError, setCheckError] = useState(false);
const handleSubmit = () => {
if (emailRef.current?.value === "") setEmailError(true);
else setEmailError(false);
if (!checkBoxRef.current?.checked) setCheckError(true);
else setCheckError(false);
const [message, setMessage] = useState("");
const [submitting, setSubmitting] = useState(false);
const handleSubmit = async () => {
const trimmedEmail = email.trim();
let hasError = false;
setMessage("");
if (!trimmedEmail) {
setEmailError("Thông tin bắt buộc");
hasError = true;
} else if (!isValidEmail(trimmedEmail)) {
setEmailError("Email không hợp lệ");
hasError = true;
} else {
setEmailError("");
}
if (!accepted) {
setCheckError(true);
hasError = true;
} else {
setCheckError(false);
}
if (hasError) return;
setSubmitting(true);
try {
await subscribeNewsletterEmail(trimmedEmail);
setEmail("");
setAccepted(false);
setMessage("Đăng ký nhận thông tin thành công.");
} catch (error) {
setMessage(error instanceof Error ? error.message : "Không thể đăng ký nhận thông tin.");
} finally {
setSubmitting(false);
}
};
return (
......@@ -58,26 +94,31 @@ function Footer() {
<div className="mt-5">
<div className="flex w-full max-w-[350px] gap-2">
<input
ref={emailRef}
value={email}
onChange={(event) => setEmail(event.target.value)}
className="h-12 flex-1 rounded-[4px] border border-[#31458d] bg-[#29418f] px-4 text-[15px] text-white placeholder:text-[#84a1ef] outline-hidden"
type="email"
placeholder="Nhập email của bạn"
/>
<button
type="button"
onClick={handleSubmit}
className="flex h-12 w-12 items-center justify-center rounded-[4px] bg-[#f7b500] text-[#203067] transition-colors hover:bg-[#ffca30]"
disabled={submitting}
className="flex h-12 w-12 items-center justify-center rounded-[4px] bg-[#f7b500] text-[#203067] transition-colors hover:bg-[#ffca30] disabled:cursor-not-allowed disabled:opacity-70"
aria-label="Đăng ký nhận thông tin"
>
<SendHorizonal className="h-5 w-5" />
<SendHorizontal className="h-5 w-5" />
</button>
</div>
{emailError ? (
<p className="mt-2 text-[12px] text-[#ff9b9b]">Thông tin bắt buộc</p>
<p className="mt-2 text-[12px] text-[#ff9b9b]">{emailError}</p>
) : null}
<div className="mt-3 flex items-center gap-2">
<input
ref={checkBoxRef}
checked={accepted}
onChange={(event) => setAccepted(event.target.checked)}
type="checkbox"
id="footer-check"
className="h-4 w-4 rounded border-white/30 bg-transparent accent-[#f7b500]"
......@@ -95,6 +136,10 @@ function Footer() {
Bạn cần đồng ý với Điều khoản nhận email
</p>
) : null}
{message ? (
<p className="mt-2 text-[12px] text-[#b8d8ff]">{message}</p>
) : null}
</div>
</div>
......
"use client";
import { Suspense } from "react";
import { usePathname, useRouter, useSearchParams } from "next/navigation";
import { useQuery } from "@tanstack/react-query";
import { Play } from "lucide-react";
import ImageNext from "@/components/shared/image-next";
import { Pagination } from "@/components/base/pagination";
import { Spinner } from "@/components/ui/spinner";
import { fetchClientVideos } from "@/lib/api/videos";
const PAGE_SIZE = 10;
function VideoPageContent() {
const router = useRouter();
const pathname = usePathname();
const searchParams = useSearchParams();
const pageFromUrl = Number(searchParams.get("page") ?? "1");
const page = Number.isFinite(pageFromUrl) && pageFromUrl > 0 ? Math.floor(pageFromUrl) : 1;
const videosQuery = useQuery({
queryKey: ["video-page", page, PAGE_SIZE],
queryFn: () => fetchClientVideos({ page, pageSize: PAGE_SIZE }),
staleTime: 60 * 1000,
});
const videos = videosQuery.data?.rows ?? [];
const totalPages = videosQuery.data?.totalPages ?? 1;
const currentPage = videosQuery.data?.page ?? page;
const updatePage = (nextPage: number) => {
const params = new URLSearchParams(searchParams.toString());
if (nextPage > 1) {
params.set("page", String(nextPage));
} else {
params.delete("page");
}
const queryString = params.toString();
router.push(queryString ? `${pathname}?${queryString}` : pathname, { scroll: false });
};
return (
<div className="min-h-screen bg-[#fbfbfa]">
<div className="container mx-auto px-4 py-8 sm:px-6 lg:px-10 lg:py-10">
<div className="mb-8">
<h1 className="text-3xl font-bold leading-tight text-[#111827] md:text-4xl">
Video
</h1>
<div className="mt-2 h-[3px] w-16 rounded-full bg-[#f5a400]" />
</div>
{videosQuery.isLoading ? (
<div className="grid gap-6 md:grid-cols-2">
{Array.from({ length: 4 }).map((_, index) => (
<div
key={`video-page-loading-${index}`}
className="h-[280px] animate-pulse rounded-[18px] bg-[#edf1f7]"
/>
))}
</div>
) : videosQuery.isError ? (
<div className="rounded-2xl border border-[#edf1f5] bg-white px-6 py-12 text-center text-gray-600">
Không thể tải danh sách video.
</div>
) : videos.length ? (
<div className="space-y-8">
<div className="grid gap-6 md:grid-cols-2">
{videos.map((video) => (
<a
key={video.id}
href={video.watchUrl}
target="_blank"
rel="noreferrer"
className="group overflow-hidden rounded-[18px] border border-[#e5ebf4] bg-white shadow-[0_12px_30px_rgba(31,59,124,0.08)] transition-all hover:-translate-y-0.5 hover:shadow-[0_18px_38px_rgba(31,59,124,0.14)]"
>
<div className="relative aspect-video overflow-hidden bg-[#edf1f5]">
<ImageNext
src={video.thumbnail}
alt={video.name}
width={900}
height={506}
className="h-full w-full object-cover transition-transform duration-500 group-hover:scale-[1.03]"
/>
<div className="absolute inset-0 bg-black/20" />
<div className="absolute inset-0 flex items-center justify-center">
<span className="flex h-14 w-14 items-center justify-center rounded-full bg-white/92 text-[#24469c] shadow-[0_12px_30px_rgba(0,0,0,0.2)]">
<Play className="ml-1 h-6 w-6 fill-current" />
</span>
</div>
</div>
<div className="p-4 sm:p-5">
<h2 className="line-clamp-2 text-[17px] font-bold leading-snug text-[#1f3f91] transition-colors group-hover:text-[#0f4386]">
{video.name}
</h2>
</div>
</a>
))}
</div>
{totalPages > 1 ? (
<div className="flex justify-center">
<Pagination
pageCount={totalPages}
page={currentPage}
onChangePage={updatePage}
onGoToPreviousPage={() => updatePage(Math.max(1, currentPage - 1))}
onGoToNextPage={() => updatePage(Math.min(totalPages, currentPage + 1))}
/>
</div>
) : null}
</div>
) : (
<div className="rounded-2xl border border-[#edf1f5] bg-white px-6 py-12 text-center text-gray-600">
Chưa có video nào.
</div>
)}
</div>
</div>
);
}
export default function Page() {
return (
<div className="container flex justify-center items-center h-full py-20">
Trang video đang được xây dựng
<Suspense
fallback={
<div className="flex min-h-screen items-center justify-center bg-[#fbfbfa]">
<Spinner className="size-8" />
</div>
}
>
<VideoPageContent />
</Suspense>
);
}
......@@ -36,7 +36,6 @@ import { Switch } from "@/components/ui/switch";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Textarea } from "@/components/ui/textarea";
import type { AdminMediaItem } from "@/mockdata/admin-news";
import { readAdminMediaItems } from "@/mockdata/admin-news";
import {
type BaseConfigBannerItem,
type BaseConfigBranchItem,
......@@ -46,7 +45,6 @@ import {
EMPTY_BASE_CONFIG_BRANCH,
cloneBaseConfigData,
createBaseConfigItemId,
getMediaMap,
persistBaseConfig,
readBaseConfig,
sortBaseConfigBanners,
......@@ -327,10 +325,12 @@ export default function AdminBaseConfigPage() {
React.useEffect(() => {
setConfig(readBaseConfig());
setMediaItems(readAdminMediaItems());
}, []);
const mediaMap = React.useMemo(() => getMediaMap(mediaItems), [mediaItems]);
const mediaMap = React.useMemo(
() => new Map(mediaItems.map((item) => [item.id, item])),
[mediaItems],
);
const sortedBanners = React.useMemo(
() => (config ? sortBaseConfigBanners(config.banners) : []),
[config],
......@@ -980,41 +980,10 @@ export default function AdminBaseConfigPage() {
</>
) : (
<div className="rounded-3xl border border-dashed border-[#063e8e]/15 bg-white px-5 py-10 text-center text-sm text-gray-500">
Chua c? chi nh?nh n?o. H?y th?m chi nh?nh d? b?t d?u c?u h?nh.
Chưa có chi nhánh nào. Hãy thêm chi nhánh để bắt đầu cấu hình
</div>
)}
</div>
<div className="hidden rounded-[28px] border border-[#063e8e]/10 bg-gradient-to-br from-[#063e8e] to-[#0f4a9f] p-6 text-white shadow-[0_16px_30px_rgba(6,62,142,0.18)] lg:block">
<div className="text-xs font-semibold uppercase tracking-[0.18em] text-white/75">
Preview chi nhánh
</div>
{currentBranch ? (
<>
<div className="mt-4 text-2xl font-semibold">{currentBranch.branchName}</div>
<div className="mt-6 space-y-4 text-sm leading-6">
<div className="flex gap-3">
<MapPin className="mt-1 h-4 w-4 shrink-0 text-white/80" />
<span>{currentBranch.address || "Chưa cập nhật địa chỉ"}</span>
</div>
<div className="flex gap-3">
<Phone className="mt-1 h-4 w-4 shrink-0 text-white/80" />
<span>{currentBranch.hotline || "Chưa cập nhật hotline"}</span>
</div>
<div className="flex gap-3">
<Mail className="mt-1 h-4 w-4 shrink-0 text-white/80" />
<span>{currentBranch.email || "Chưa cập nhật email"}</span>
</div>
<div className="flex gap-3">
<Globe className="mt-1 h-4 w-4 shrink-0 text-white/80" />
<span>{currentBranch.fax || "Chưa cập nhật fax"}</span>
</div>
</div>
</>
) : (
<div className="mt-6 text-sm text-white/80">Không có dữ liệu chi nhánh để preview.</div>
)}
</div>
</CardContent>
</Card>
</TabsContent>
......@@ -1123,7 +1092,14 @@ export default function AdminBaseConfigPage() {
open={imagePickerOpen}
selectedId={itemForm.imageId}
onOpenChange={setImagePickerOpen}
onSelect={(item) => setItemForm((previous) => ({ ...previous, imageId: item.id }))}
onSelect={(item) => {
setMediaItems((previous) => {
const nextMap = new Map(previous.map((entry) => [entry.id, entry]));
nextMap.set(item.id, item);
return Array.from(nextMap.values());
});
setItemForm((previous) => ({ ...previous, imageId: item.id }));
}}
/>
<AdminDeleteDialog
......
......@@ -8,6 +8,14 @@ import { AdminDeleteDialog } from "@/components/admin/admin-delete-dialog";
import { AdminRowActions } from "@/components/admin/admin-row-actions";
import { AdminTableLayout } from "@/components/admin/admin-table-layout";
import { ContactManagementDetailDialog } from "@/components/admin/contact-management-detail-dialog";
import { Pagination } from "@/components/base/pagination";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import {
Table,
TableBody,
......@@ -16,48 +24,121 @@ import {
TableHeader,
TableRow,
} from "@/components/ui/table";
import type { NewsletterSubscription } from "@/api/models/newsletterSubscription";
import {
type NewsletterSubscriptionItem,
persistNewsletterSubscriptions,
readNewsletterSubscriptions,
} from "@/mockdata/contact-management";
deleteNewsletterSubscription,
fetchNewsletterSubscriptions,
markNewsletterSubscriptionSeen,
} from "@/lib/api/newsletter-subscriptions";
type SeenFilter = "all" | "seen" | "unseen";
const PAGE_SIZE = 10;
const selectTriggerClassName =
"h-10 w-full rounded-xl border-[#063e8e]/15 bg-white text-gray-700 sm:w-[180px]";
const selectContentClassName = "rounded-xl border-[#063e8e]/15 bg-white text-gray-700";
const selectItemClassName = "text-gray-700 focus:bg-[#063e8e]/10 focus:text-[#063e8e]";
function formatDateTime(value: string) {
return dayjs(value).format("DD/MM/YYYY HH:mm");
}
function buildNewsletterFilters(search: string, seenFilter: SeenFilter) {
const filters: string[] = [];
const keyword = search.trim();
if (keyword) {
filters.push(`email@=${keyword}`);
}
if (seenFilter === "seen") {
filters.push("is_seen==true");
}
if (seenFilter === "unseen") {
filters.push("is_seen==false");
}
return filters.join(",");
}
export default function AdminNewsletterEmailsPage() {
const [items, setItems] = React.useState<NewsletterSubscriptionItem[]>([]);
const [items, setItems] = React.useState<NewsletterSubscription[]>([]);
const [search, setSearch] = React.useState("");
const [seenFilter, setSeenFilter] = React.useState<SeenFilter>("all");
const [page, setPage] = React.useState(1);
const [totalItems, setTotalItems] = React.useState(0);
const [ready, setReady] = React.useState(false);
const [detailTarget, setDetailTarget] = React.useState<NewsletterSubscriptionItem | null>(null);
const [deleteTarget, setDeleteTarget] = React.useState<NewsletterSubscriptionItem | null>(null);
const [detailTarget, setDetailTarget] = React.useState<NewsletterSubscription | null>(null);
const [deleteTarget, setDeleteTarget] = React.useState<NewsletterSubscription | null>(null);
React.useEffect(() => {
setItems(readNewsletterSubscriptions());
const loadItems = React.useCallback(async () => {
setReady(false);
try {
const data = await fetchNewsletterSubscriptions({
page,
pageSize: PAGE_SIZE,
filters: buildNewsletterFilters(search, seenFilter),
});
setItems(data.rows);
setTotalItems(data.count);
} catch (error) {
toast.error(error instanceof Error ? error.message : "Không thể tải danh sách email đăng ký");
setItems([]);
setTotalItems(0);
} finally {
setReady(true);
}, []);
}
}, [page, search, seenFilter]);
const filteredItems = React.useMemo(() => {
const keyword = search.trim().toLowerCase();
if (!keyword) return items;
React.useEffect(() => {
void loadItems();
}, [loadItems]);
return items.filter(
(item) =>
item.email.toLowerCase().includes(keyword) ||
item.id.toLowerCase().includes(keyword) ||
formatDateTime(item.submittedAt).toLowerCase().includes(keyword),
);
}, [items, search]);
const totalPages = Math.max(1, Math.ceil(totalItems / PAGE_SIZE));
const handleSearchChange = (value: string) => {
setSearch(value);
setPage(1);
};
const handleDelete = () => {
const handleSeenFilterChange = (value: SeenFilter) => {
setSeenFilter(value);
setPage(1);
};
const handleDelete = async () => {
if (!deleteTarget) return;
const nextItems = items.filter((item) => item.id !== deleteTarget.id);
setItems(nextItems);
persistNewsletterSubscriptions(nextItems);
try {
await deleteNewsletterSubscription(deleteTarget.id);
toast.success("Đã xóa email đăng ký nhận thông tin");
setDeleteTarget(null);
await loadItems();
} catch (error) {
toast.error(error instanceof Error ? error.message : "Không thể xóa email đăng ký");
}
};
const handleViewDetail = async (item: NewsletterSubscription) => {
setDetailTarget(item);
if (item.is_seen) return;
try {
await markNewsletterSubscriptionSeen(item.id);
const seenAt = new Date().toISOString();
const nextItem = { ...item, is_seen: true, seen_at: item.seen_at ?? seenAt };
setItems((currentItems) =>
currentItems.map((currentItem) => (currentItem.id === item.id ? nextItem : currentItem)),
);
setDetailTarget(nextItem);
} catch (error) {
toast.error(error instanceof Error ? error.message : "Không thể cập nhật trạng thái đã xem");
}
};
return (
......@@ -65,12 +146,30 @@ export default function AdminNewsletterEmailsPage() {
<AdminTableLayout
searchValue={search}
searchPlaceholder="Tìm kiếm email đăng ký..."
filters={
<Select value={seenFilter} onValueChange={(value) => handleSeenFilterChange(value as SeenFilter)}>
<SelectTrigger className={selectTriggerClassName}>
<SelectValue placeholder="Trạng thái" />
</SelectTrigger>
<SelectContent className={selectContentClassName}>
<SelectItem value="all" className={selectItemClassName}>
Tất cả trạng thái
</SelectItem>
<SelectItem value="unseen" className={selectItemClassName}>
Chưa xem
</SelectItem>
<SelectItem value="seen" className={selectItemClassName}>
Đã xem
</SelectItem>
</SelectContent>
</Select>
}
actionMeta={
<div className="rounded-xl border border-[#063e8e]/15 bg-[#f8fbff] px-4 py-2 text-sm font-semibold text-[#163b73]">
Tổng số email: {items.length}
Tổng số email: {totalItems}
</div>
}
onSearchChange={setSearch}
onSearchChange={handleSearchChange}
>
<Table>
<TableHeader>
......@@ -78,6 +177,7 @@ export default function AdminNewsletterEmailsPage() {
<TableHead className="w-16 py-4 text-center text-white">STT</TableHead>
<TableHead className="py-4 text-center text-white">Email</TableHead>
<TableHead className="w-[190px] py-4 text-center text-white">Ngày gửi</TableHead>
<TableHead className="w-[130px] py-4 text-center text-white">Trạng thái</TableHead>
<TableHead className="w-[130px] py-4 text-center text-white">Thao tác</TableHead>
</TableRow>
</TableHeader>
......@@ -85,25 +185,25 @@ export default function AdminNewsletterEmailsPage() {
{!ready ? (
Array.from({ length: 4 }).map((_, index) => (
<TableRow key={`loading-${index}`}>
<TableCell colSpan={4} className="px-4 py-4">
<TableCell colSpan={5} className="px-4 py-4">
<div className="h-10 animate-pulse rounded-xl bg-[#063e8e]/10" />
</TableCell>
</TableRow>
))
) : filteredItems.length === 0 ? (
) : items.length === 0 ? (
<TableRow>
<TableCell colSpan={4} className="py-16 text-center text-gray-400">
<TableCell colSpan={5} className="py-16 text-center text-gray-400">
Không có email đăng ký nào
</TableCell>
</TableRow>
) : (
filteredItems.map((item, index) => (
items.map((item, index) => (
<TableRow
key={item.id}
className={index % 2 === 0 ? "bg-white" : "bg-[#063e8e]/3"}
>
<TableCell className="py-3 text-center text-sm text-gray-500">
{index + 1}
{(page - 1) * PAGE_SIZE + index + 1}
</TableCell>
<TableCell className="py-3 text-sm font-medium text-gray-800">
<div className="flex items-center gap-3">
......@@ -114,12 +214,23 @@ export default function AdminNewsletterEmailsPage() {
</div>
</TableCell>
<TableCell className="py-3 text-center text-sm text-gray-700">
{formatDateTime(item.submittedAt)}
{formatDateTime(item.created_at)}
</TableCell>
<TableCell className="py-3 text-center">
<span
className={
item.is_seen
? "inline-flex rounded-full bg-[#edf7ee] px-3 py-1 text-xs font-semibold text-[#16803d]"
: "inline-flex rounded-full bg-[#fff4e5] px-3 py-1 text-xs font-semibold text-[#c7760d]"
}
>
{item.is_seen ? "Đã xem" : "Chưa xem"}
</span>
</TableCell>
<TableCell className="py-3 text-center">
<AdminRowActions
actions={[
{ kind: "view", label: "Xem chi tiết email", onClick: () => setDetailTarget(item) },
{ kind: "view", label: "Xem chi tiết email", onClick: () => void handleViewDetail(item) },
{ kind: "delete", label: "Xóa email đăng ký", onClick: () => setDeleteTarget(item) },
]}
/>
......@@ -131,6 +242,18 @@ export default function AdminNewsletterEmailsPage() {
</Table>
</AdminTableLayout>
{totalPages > 1 ? (
<div className="flex justify-center">
<Pagination
pageCount={totalPages}
page={page}
onChangePage={setPage}
onGoToPreviousPage={() => setPage((currentPage) => Math.max(1, currentPage - 1))}
onGoToNextPage={() => setPage((currentPage) => Math.min(totalPages, currentPage + 1))}
/>
</div>
) : null}
<ContactManagementDetailDialog
open={!!detailTarget}
title="Chi tiết email đăng ký nhận thông tin"
......@@ -143,7 +266,12 @@ export default function AdminNewsletterEmailsPage() {
title: "Thông tin đăng ký",
fields: [
{ label: "Email", value: detailTarget.email },
{ label: "Ngày gửi", value: formatDateTime(detailTarget.submittedAt) },
{ label: "Ngày gửi", value: formatDateTime(detailTarget.created_at) },
{ label: "Trạng thái", value: detailTarget.is_seen ? "Đã xem" : "Chưa xem" },
{
label: "Ngày xem",
value: detailTarget.seen_at ? formatDateTime(detailTarget.seen_at) : "Chưa xem",
},
],
},
]
......
......@@ -7,8 +7,6 @@ import { useParams, usePathname, useRouter, useSearchParams } from "next/navigat
import { toast } from "sonner";
import {
ArrowLeft,
ChevronLeft,
ChevronRight,
FileText,
Plus,
Star,
......@@ -17,6 +15,7 @@ import { AdminDeleteDialog } from "@/components/admin/admin-delete-dialog";
import { AdminRowActions } from "@/components/admin/admin-row-actions";
import { AdminStatsGrid } from "@/components/admin/admin-stats-grid";
import { AdminTableLayout } from "@/components/admin/admin-table-layout";
import { Pagination } from "@/components/base/pagination";
import { SafeNextImage } from "@/components/admin/safe-next-image";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
......@@ -38,6 +37,8 @@ import {
import { ADMIN_NEWS_TYPE_LABELS } from "@/mockdata/admin-news";
import { buildHeaderCategoryTree } from "@/mockdata/header-config";
const PAGE_SIZE = 10;
function formatDateTime(value: string) {
return value ? dayjs(value).format("DD/MM/YYYY HH:mm") : "—";
}
......@@ -83,11 +84,11 @@ export default function HeaderCategoryPostsPage() {
const [ready, setReady] = React.useState(false);
const [deleteTarget, setDeleteTarget] = React.useState<CmsNewsItem | null>(null);
const didMountRef = React.useRef(false);
const [total, setTotal] = React.useState(0);
const [page, setPage] = React.useState(() => {
const parsedPage = Number(searchParams.get("page") ?? 1);
return Number.isFinite(parsedPage) && parsedPage > 0 ? Math.floor(parsedPage) : 1;
});
const [pageSize] = React.useState(20);
const listQueryString = React.useMemo(() => {
const nextParams = new URLSearchParams();
......@@ -113,14 +114,27 @@ export default function HeaderCategoryPostsPage() {
const load = async () => {
try {
const [{ items: newsItems }, headerConfig] = await Promise.all([
fetchCmsNewsItems(),
const keyword = search.trim();
const filters = [
`category.id==${categoryId}`,
keyword ? `title@=${keyword}|slug@=${keyword}` : "",
].filter(Boolean).join(",");
const [newsData, headerConfig] = await Promise.all([
fetchCmsNewsItems({
page,
pageSize: PAGE_SIZE,
sortField: "created_at",
sortOrder: "desc",
filters,
}),
fetchHeaderConfigItems(),
]);
if (cancelled) return;
setItems(newsItems);
setItems(newsData.items);
setTotal(newsData.total);
setHeaderItems(headerConfig.items);
setReady(true);
} catch (error) {
......@@ -135,7 +149,7 @@ export default function HeaderCategoryPostsPage() {
return () => {
cancelled = true;
};
}, []);
}, [categoryId, page, search]);
const flatCategories = React.useMemo(() => {
return flattenTree(buildHeaderCategoryTree(headerItems));
......@@ -150,45 +164,7 @@ export default function HeaderCategoryPostsPage() {
category && (category.type === "page" || category.type === "news"),
);
const categoryPosts = React.useMemo(() => {
return items
.filter(
(item) =>
item.header_category_id === categoryId ||
item.category_ids.includes(categoryId),
)
.sort((left, right) => {
const leftFeatured = left.type === "tintuc" && left.is_featured ? 1 : 0;
const rightFeatured = right.type === "tintuc" && right.is_featured ? 1 : 0;
if (leftFeatured !== rightFeatured) {
return rightFeatured - leftFeatured;
}
const leftTime = new Date(left.published_at || left.created_at).getTime();
const rightTime = new Date(right.published_at || right.created_at).getTime();
return rightTime - leftTime;
});
}, [categoryId, items]);
const filteredPosts = React.useMemo(() => {
const keyword = search.trim().toLowerCase();
if (!keyword) return categoryPosts;
return categoryPosts.filter((item) => {
return (
item.title.toLowerCase().includes(keyword) ||
item.slug.toLowerCase().includes(keyword)
);
});
}, [categoryPosts, search]);
const totalPages = Math.ceil(filteredPosts.length / pageSize);
const paginatedPosts = React.useMemo(() => {
const start = (page - 1) * pageSize;
return filteredPosts.slice(start, start + pageSize);
}, [filteredPosts, page, pageSize]);
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE));
const isSinglePostCategory = category?.type === "page";
const createHref = `/admin/header-config/${categoryId}/posts/new`;
......@@ -227,21 +203,21 @@ export default function HeaderCategoryPostsPage() {
return [
{
label: "Tổng bài viết",
value: categoryPosts.length,
value: total,
icon: <FileText className="h-4 w-4 text-[#063e8e]" />,
},
{
label: "Đang hiển thị",
value: categoryPosts.filter((item) => !item.is_hidden).length,
value: items.filter((item) => !item.is_hidden).length,
icon: <FileText className="h-4 w-4 text-[#063e8e]" />,
},
{
label: "Tin nổi bật",
value: categoryPosts.filter((item) => item.type === "tintuc" && item.is_featured).length,
value: items.filter((item) => item.type === "tintuc" && item.is_featured).length,
icon: <Star className="h-4 w-4 text-[#063e8e]" />,
},
];
}, [categoryPosts]);
}, [items, total]);
const handleDelete = async () => {
if (!deleteTarget) return;
......@@ -249,6 +225,7 @@ export default function HeaderCategoryPostsPage() {
try {
await deleteCmsNewsItem(deleteTarget.id);
setItems((current) => current.filter((item) => item.id !== deleteTarget.id));
setTotal((current) => Math.max(0, current - 1));
toast.success("Đã xóa bài viết");
setDeleteTarget(null);
} catch (error) {
......@@ -304,7 +281,7 @@ export default function HeaderCategoryPostsPage() {
searchPlaceholder="Tìm kiếm bài viết thuộc danh mục..."
actionLabel={isSinglePostCategory ? "Thêm bài viết trang" : "Thêm bài viết"}
actionIcon={<Plus className="mr-2 h-4 w-4" />}
actionDisabled={isSinglePostCategory && categoryPosts.length >= 1}
actionDisabled={isSinglePostCategory && total >= 1}
onSearchChange={setSearch}
onActionClick={() =>
router.push(`${createHref}?returnTo=${encodeURIComponent(listPath)}`)
......@@ -337,16 +314,16 @@ export default function HeaderCategoryPostsPage() {
<TableBody>
{!ready ? (
<HeaderCategoryPostsLoading />
) : filteredPosts.length === 0 ? (
) : items.length === 0 ? (
<TableRow>
<TableCell colSpan={6} className="py-12 text-center text-sm text-gray-700">
{categoryPosts.length === 0
{total === 0
? "Danh mục này chưa có bài viết nào."
: "Không có bài viết nào phù hợp."}
</TableCell>
</TableRow>
) : (
paginatedPosts.map((item, index) => (
items.map((item, index) => (
<TableRow
key={item.id}
className={index % 2 === 0 ? "bg-white" : "bg-[#063e8e]/[0.03]"}
......@@ -430,60 +407,11 @@ export default function HeaderCategoryPostsPage() {
{totalPages > 1 && (
<div className="flex items-center justify-between border-t border-[#063e8e]/10 px-4 py-3">
<div className="text-sm text-gray-700">
{"Hi\u1ec3n th\u1ecb"} {(page - 1) * pageSize + 1} {"\u0111\u1ebfn"}{" "}
{Math.min(page * pageSize, filteredPosts.length)} {"c\u1ee7a"}{" "}
{filteredPosts.length} {"b\u00e0i vi\u1ebft"}
</div>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="icon"
className="h-8 w-8 border-[#063e8e]/15 bg-white text-[#063e8e] hover:bg-[#063e8e]/10"
onClick={() => handlePageChange(page - 1)}
disabled={page === 1}
>
<ChevronLeft className="h-4 w-4" />
</Button>
<div className="flex items-center gap-1">
{Array.from({ length: Math.min(totalPages, 5) }, (_, index) => {
let pageNum;
if (totalPages <= 5) {
pageNum = index + 1;
} else if (page <= 3) {
pageNum = index + 1;
} else if (page >= totalPages - 2) {
pageNum = totalPages - 4 + index;
} else {
pageNum = page - 2 + index;
}
return (
<Button
key={pageNum}
variant={page === pageNum ? "default" : "outline"}
size="icon"
className={
page === pageNum
? "h-8 w-8 bg-[#063e8e] text-white hover:bg-[#063e8e]/90"
: "h-8 w-8 border-[#063e8e]/15 bg-white text-[#063e8e] hover:bg-[#063e8e]/10"
}
onClick={() => handlePageChange(pageNum)}
>
{pageNum}
</Button>
);
})}
</div>
<Button
variant="outline"
size="icon"
className="h-8 w-8 border-[#063e8e]/15 bg-white text-[#063e8e] hover:bg-[#063e8e]/10"
onClick={() => handlePageChange(page + 1)}
disabled={page === totalPages}
>
<ChevronRight className="h-4 w-4" />
</Button>
{"Hi\u1ec3n th\u1ecb"} {(page - 1) * PAGE_SIZE + 1} {"\u0111\u1ebfn"}{" "}
{Math.min(page * PAGE_SIZE, total)} {"c\u1ee7a"}{" "}
{total} {"b\u00e0i vi\u1ebft"}
</div>
<Pagination page={page} pageCount={totalPages} onChangePage={handlePageChange} />
</div>
)}
</AdminTableLayout>
......
......@@ -2,7 +2,6 @@
import * as React from "react";
import {
Edit,
Image as ImageIcon,
Plus,
Save,
......@@ -14,6 +13,7 @@ import { toast } from "sonner";
import { AdminDeleteDialog } from "@/components/admin/admin-delete-dialog";
import { AdminTableLayout } from "@/components/admin/admin-table-layout";
import { SafeNextImage } from "@/components/admin/safe-next-image";
import { Pagination } from "@/components/base/pagination";
import { Button } from "@/components/ui/button";
import {
Dialog,
......@@ -23,44 +23,41 @@ import {
} from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Textarea } from "@/components/ui/textarea";
import {
type AdminMediaItem,
createAdminMediaId,
persistAdminMediaItems,
readAdminMediaItems,
} from "@/mockdata/admin-news";
type CmsFileItem,
deleteCmsFile,
fetchCmsFiles,
resolveCmsFileUrl,
uploadCmsFile,
} from "@/lib/api/files";
const PAGE_SIZE = 10;
const inputClassName =
"rounded-2xl border-[#063e8e]/15 bg-white text-gray-700 shadow-sm placeholder:text-gray-400 focus-visible:ring-[#063e8e]/20";
type MediaFormValues = {
id?: string;
file: File | null;
name: string;
alt: string;
url: string;
mime: string;
size: number;
source: "seed" | "upload";
previewUrl: string;
};
const EMPTY_MEDIA_FORM: MediaFormValues = {
file: null,
name: "",
alt: "",
url: "",
mime: "image/*",
size: 0,
source: "upload",
previewUrl: "",
};
function formatFileSize(size: number) {
function formatFileSize(size?: number | null) {
if (!size) return "Ảnh hệ thống";
if (size < 1024) return `${size} B`;
if (size < 1024 * 1024) return `${(size / 1024).toFixed(1)} KB`;
return `${(size / (1024 * 1024)).toFixed(1)} MB`;
}
function formatDate(value: string) {
function formatDate(value?: string | null) {
if (!value) return "-";
return new Date(value).toLocaleString("vi-VN", {
day: "2-digit",
month: "2-digit",
......@@ -70,6 +67,22 @@ function formatDate(value: string) {
});
}
function getFileSize(item: CmsFileItem) {
const importInfo = item as CmsFileItem & {
size?: number | null;
file_size?: number | null;
import_info?: { size?: number; file_size?: number } | null;
};
return (
importInfo.size ??
importInfo.file_size ??
importInfo.import_info?.size ??
importInfo.import_info?.file_size ??
0
);
}
function MediaCardSkeleton() {
return (
<div className="overflow-hidden rounded-[28px] border border-[#063e8e]/10 bg-white shadow-[0_18px_45px_rgba(6,62,142,0.08)]">
......@@ -85,14 +98,14 @@ function MediaCardSkeleton() {
interface MediaFormDialogProps {
open: boolean;
initial: AdminMediaItem | null;
saving: boolean;
onOpenChange: (open: boolean) => void;
onSave: (data: MediaFormValues) => void;
onSave: (data: MediaFormValues) => Promise<void>;
}
function MediaFormDialog({
open,
initial,
saving,
onOpenChange,
onSave,
}: MediaFormDialogProps) {
......@@ -101,67 +114,48 @@ function MediaFormDialog({
React.useEffect(() => {
if (!open) return;
setForm(
initial
? {
id: initial.id,
name: initial.name,
alt: initial.alt,
url: initial.url,
mime: initial.mime,
size: initial.size,
source: initial.source,
}
: EMPTY_MEDIA_FORM,
);
}, [initial, open]);
const handleField = <K extends keyof MediaFormValues>(
key: K,
value: MediaFormValues[K],
) => {
setForm((previous) => ({ ...previous, [key]: value }));
};
setForm(EMPTY_MEDIA_FORM);
}, [open]);
const handleUpload = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (!file) return;
const reader = new FileReader();
reader.onload = () => {
const previewUrl = URL.createObjectURL(file);
const defaultName = file.name.replace(/\.[^.]+$/, "");
setForm((previous) => ({
...previous,
setForm((previous) => {
if (previous.previewUrl) {
URL.revokeObjectURL(previous.previewUrl);
}
return {
file,
name: previous.name || defaultName,
alt: previous.alt || defaultName,
url: typeof reader.result === "string" ? reader.result : previous.url,
mime: file.type || "image/*",
size: file.size,
source: "upload",
}));
previewUrl,
};
});
reader.readAsDataURL(file);
event.target.value = "";
};
const handleSave = () => {
if (!form.name.trim()) {
toast.error("Vui lòng nhập tên ảnh");
return;
React.useEffect(() => {
return () => {
if (form.previewUrl) {
URL.revokeObjectURL(form.previewUrl);
}
};
}, [form.previewUrl]);
if (!form.url.trim()) {
toast.error("Vui lòng chọn ảnh hoặc nhập liên kết ảnh");
const handleSave = async () => {
if (!form.file) {
toast.error("Vui lòng chọn ảnh cần tải lên");
return;
}
onSave({
await onSave({
...form,
name: form.name.trim(),
alt: form.alt.trim() || form.name.trim(),
url: form.url.trim(),
name: form.name.trim() || form.file.name,
});
};
......@@ -170,7 +164,7 @@ function MediaFormDialog({
<DialogContent className="flex max-h-[calc(100dvh-32px)] w-[calc(100vw-32px)] max-w-4xl flex-col overflow-hidden rounded-[32px] border border-[#063e8e]/15 bg-white p-0 shadow-[0_26px_70px_rgba(15,23,42,0.24)]">
<DialogHeader className="shrink-0 border-b border-[#063e8e]/10 px-6 py-5 sm:px-7">
<DialogTitle className="text-xl font-semibold text-[#063e8e]">
{initial ? "Chỉnh sửa ảnh" : "Tải ảnh lên"}
Tải ảnh lên
</DialogTitle>
</DialogHeader>
......@@ -179,10 +173,10 @@ function MediaFormDialog({
<div className="space-y-4">
<div className="overflow-hidden rounded-[28px] border border-[#063e8e]/10 bg-white shadow-[inset_0_1px_0_rgba(255,255,255,0.8)]">
<div className="relative aspect-[16/10] bg-[radial-gradient(circle_at_top,#d9e8ff_0%,#f7faff_58%,#ffffff_100%)]">
{form.url ? (
{form.previewUrl ? (
<SafeNextImage
src={form.url}
alt={form.alt || form.name}
src={form.previewUrl}
alt={form.name}
fill
className="object-contain p-4"
/>
......@@ -196,7 +190,7 @@ function MediaFormDialog({
Chưa có ảnh nào được chọn
</p>
<p className="text-xs text-slate-500">
Kéo thả hoặc tải ảnh từ máy tính của bạn
Chọn ảnh từ máy tính để tải lên hệ thống
</p>
</div>
</div>
......@@ -218,7 +212,7 @@ function MediaFormDialog({
Tải ảnh từ máy tính
</p>
<p className="text-sm text-slate-500">
Hỗ trợ ảnh JPG, PNG, WEBP. Dung lượng sẽ được lưu theo file bạn chọn.
Hỗ trợ ảnh JPG, PNG, WEBP. Ảnh sẽ được lưu vào API /file/upload.
</p>
<Button
type="button"
......@@ -237,50 +231,23 @@ function MediaFormDialog({
<div className="p-6 lg:p-7">
<div className="space-y-5">
<div className="space-y-2">
<Label className="text-sm font-medium text-slate-700">Tiêu đề ảnh</Label>
<Label className="text-sm font-medium text-slate-700">Tên ảnh</Label>
<Input
value={form.name}
onChange={(event) => handleField("name", event.target.value)}
placeholder="Nhập tiêu đề ảnh"
className={inputClassName}
/>
</div>
<div className="space-y-2">
<Label className="text-sm font-medium text-slate-700">Mô tả alt</Label>
<Input
value={form.alt}
onChange={(event) => handleField("alt", event.target.value)}
placeholder="Nhập mô tả alt"
className={inputClassName}
/>
</div>
<div className="space-y-2">
<Label className="text-sm font-medium text-slate-700">Liên kết ảnh</Label>
<Input
value={form.url}
onChange={(event) => handleField("url", event.target.value)}
placeholder="https://... hoặc data:image/..."
onChange={(event) =>
setForm((previous) => ({ ...previous, name: event.target.value }))
}
placeholder="Nhập tên ảnh"
className={inputClassName}
/>
</div>
<div className="space-y-2">
<Label className="text-sm font-medium text-slate-700">Ghi chú hiển thị</Label>
<Textarea
value={form.alt}
onChange={(event) => handleField("alt", event.target.value)}
placeholder="Nhập nội dung mô tả ngắn cho ảnh"
rows={4}
className={`${inputClassName} min-h-[120px] resize-none`}
/>
</div>
<div className="rounded-[24px] border border-[#063e8e]/10 bg-white p-4 text-sm text-slate-500">
<div className="flex items-center gap-2">
<p className="text-xs uppercase tracking-[0.14em] text-slate-400">Dung lượng</p>
<p className="font-semibold text-slate-700">{formatFileSize(form.size)}</p>
<p className="font-semibold text-slate-700">
{formatFileSize(form.file?.size)}
</p>
</div>
</div>
</div>
......@@ -294,6 +261,7 @@ function MediaFormDialog({
variant="outline"
onClick={() => onOpenChange(false)}
className="rounded-2xl border-[#063e8e]/15 bg-white text-slate-600 hover:bg-slate-50"
disabled={saving}
>
<X className="mr-2 h-4 w-4" />
Hủy
......@@ -302,9 +270,10 @@ function MediaFormDialog({
type="button"
onClick={handleSave}
className="rounded-2xl bg-[#063e8e] text-white hover:bg-[#063e8e]/90"
disabled={saving}
>
<Save className="mr-2 h-4 w-4" />
{initial ? "Lưu thay đổi" : "Tải ảnh lên"}
{saving ? "Đang tải..." : "Tải ảnh lên"}
</Button>
</div>
</div>
......@@ -314,90 +283,81 @@ function MediaFormDialog({
}
export default function AdminMediaPage() {
const [items, setItems] = React.useState<AdminMediaItem[]>([]);
const [items, setItems] = React.useState<CmsFileItem[]>([]);
const [search, setSearch] = React.useState("");
const [ready, setReady] = React.useState(false);
const [saving, setSaving] = React.useState(false);
const [dialogOpen, setDialogOpen] = React.useState(false);
const [editTarget, setEditTarget] = React.useState<AdminMediaItem | null>(null);
const [deleteTarget, setDeleteTarget] = React.useState<AdminMediaItem | null>(null);
const [deleteTarget, setDeleteTarget] = React.useState<CmsFileItem | null>(null);
const [page, setPage] = React.useState(1);
const [total, setTotal] = React.useState(0);
const load = React.useCallback(async () => {
setReady(false);
try {
const result = await fetchCmsFiles({
page,
pageSize: PAGE_SIZE,
search,
});
React.useEffect(() => {
setItems(readAdminMediaItems());
setItems(result.rows);
setTotal(result.count);
} catch (error) {
toast.error(error instanceof Error ? error.message : "Không thể tải danh sách ảnh");
setItems([]);
setTotal(0);
} finally {
setReady(true);
}, []);
}
}, [page, search]);
const filtered = React.useMemo(() => {
const keyword = search.trim().toLowerCase();
if (!keyword) return items;
React.useEffect(() => {
void load();
}, [load]);
return items.filter((item) => {
return [item.name, item.alt, item.url].some((value) =>
value.toLowerCase().includes(keyword),
);
});
}, [items, search]);
React.useEffect(() => {
setPage(1);
}, [search]);
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE));
const openCreate = () => {
setEditTarget(null);
setDialogOpen(true);
};
const openEdit = (item: AdminMediaItem) => {
setEditTarget(item);
setDialogOpen(true);
};
const handleSave = async (data: MediaFormValues) => {
if (!data.file) return;
const handleSave = (data: MediaFormValues) => {
const now = new Date().toISOString();
let nextItems: AdminMediaItem[];
if (data.id) {
nextItems = items.map((item) =>
item.id === data.id
? {
...item,
name: data.name,
alt: data.alt,
url: data.url,
mime: data.mime,
size: data.size,
source: data.source,
updated_at: now,
}
: item,
);
toast.success("Đã cập nhật ảnh");
} else {
nextItems = [
{
id: createAdminMediaId(),
name: data.name,
alt: data.alt,
url: data.url,
mime: data.mime,
size: data.size,
source: data.source,
created_at: now,
updated_at: now,
},
...items,
];
toast.success("Đã thêm ảnh mới");
}
setSaving(true);
persistAdminMediaItems(nextItems);
setItems(readAdminMediaItems());
try {
await uploadCmsFile({
file: data.file,
original: data.name,
});
toast.success("Đã tải ảnh lên");
setDialogOpen(false);
await load();
} catch (error) {
toast.error(error instanceof Error ? error.message : "Không thể tải ảnh lên");
} finally {
setSaving(false);
}
};
const handleDelete = () => {
const handleDelete = async () => {
if (!deleteTarget) return;
const nextItems = items.filter((item) => item.id !== deleteTarget.id);
setItems(nextItems);
persistAdminMediaItems(nextItems);
try {
await deleteCmsFile(deleteTarget.id);
toast.success("Đã xóa ảnh");
setDeleteTarget(null);
await load();
} catch (error) {
toast.error(error instanceof Error ? error.message : "Không thể xóa ảnh");
}
};
return (
......@@ -409,7 +369,7 @@ export default function AdminMediaPage() {
actionIcon={<Plus className="mr-2 h-4 w-4" />}
actionMeta={
<div className="rounded-xl border border-[#063e8e]/15 bg-[#f8fbff] px-4 py-2 text-sm font-semibold text-[#163b73]">
Tổng số ảnh: {items.length}
Tổng số ảnh: {total}
</div>
}
onSearchChange={setSearch}
......@@ -417,32 +377,32 @@ export default function AdminMediaPage() {
>
<div className="bg-white p-4 sm:p-5">
{!ready ? (
<div className="grid gap-5 sm:grid-cols-2 xl:grid-cols-4">
{Array.from({ length: 8 }).map((_, index) => (
<div className="grid gap-5 sm:grid-cols-2 xl:grid-cols-5">
{Array.from({ length: PAGE_SIZE }).map((_, index) => (
<MediaCardSkeleton key={`media-loading-${index}`} />
))}
</div>
) : filtered.length === 0 ? (
) : items.length === 0 ? (
<div className="flex min-h-[320px] flex-col items-center justify-center rounded-[28px] border border-dashed border-[#063e8e]/20 bg-[#fbfdff] text-center">
<div className="flex h-16 w-16 items-center justify-center rounded-[22px] bg-[#063e8e]/10 text-[#063e8e]">
<ImageIcon className="h-8 w-8" />
</div>
<h2 className="mt-5 text-lg font-semibold text-slate-800">Chưa có ảnh phù hợp</h2>
<p className="mt-2 max-w-md text-sm leading-6 text-slate-500">
H?y t?i ?nh m?i ho?c th? l?i v?i t? kh?a kh?c d? t?m d?ng h?nh ?nh b?n c?n.
Hãy tải ảnh mới hoặc thử lại với từ khóa khác để tìm đúng hình ảnh bạn cần.
</p>
</div>
) : (
<div className="grid gap-5 sm:grid-cols-2 xl:grid-cols-4">
{filtered.map((item) => (
<div className="grid gap-5 sm:grid-cols-2 xl:grid-cols-5">
{items.map((item) => (
<article
key={item.id}
className="group overflow-hidden rounded-[28px] border border-[#063e8e]/10 bg-white shadow-[0_18px_45px_rgba(6,62,142,0.08)] transition duration-300 hover:-translate-y-1 hover:shadow-[0_28px_60px_rgba(6,62,142,0.14)]"
>
<div className="relative aspect-square overflow-hidden bg-[radial-gradient(circle_at_top,#dce9ff_0%,#f8fbff_55%,#ffffff_100%)]">
<SafeNextImage
src={item.url}
alt={item.alt || item.name}
src={resolveCmsFileUrl(item.path)}
alt={item.original}
fill
className="object-contain p-4 transition duration-300 group-hover:scale-[1.03]"
/>
......@@ -453,16 +413,6 @@ export default function AdminMediaPage() {
<div className="rounded-full bg-white/90 px-3 py-1 text-xs font-semibold text-slate-700 backdrop-blur">
{item.mime.split("/")[1]?.toUpperCase() || "IMG"}
</div>
<div className="flex items-center gap-2">
<Button
type="button"
size="icon"
variant="secondary"
onClick={() => openEdit(item)}
className="h-10 w-10 rounded-2xl bg-white text-[#063e8e] shadow-lg hover:bg-white"
>
<Edit className="h-4 w-4" />
</Button>
<Button
type="button"
size="icon"
......@@ -474,24 +424,23 @@ export default function AdminMediaPage() {
</Button>
</div>
</div>
</div>
<div className="space-y-3 p-4">
<div className="space-y-1">
<h3 className="line-clamp-1 text-sm font-semibold text-slate-900">
{item.name}
{item.original}
</h3>
<p className="line-clamp-2 min-h-10 text-xs leading-5 text-slate-500">
{item.alt || "Chưa có mô tả alt cho ảnh này."}
{item.path}
</p>
</div>
<div className="flex items-center justify-between text-xs text-slate-500">
<span>{formatFileSize(item.size)}</span>
<span>{formatFileSize(getFileSize(item))}</span>
</div>
<div className="border-t border-[#063e8e]/8 pt-3 text-xs text-slate-500">
{formatDate(item.updated_at)}
{formatDate(item.created_at)}
</div>
</div>
</article>
......@@ -499,11 +448,25 @@ export default function AdminMediaPage() {
</div>
)}
</div>
{totalPages > 1 ? (
<div className="flex flex-col gap-3 border-t border-[#063e8e]/10 px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
<div className="text-sm text-gray-700">
Hiển thị {(page - 1) * PAGE_SIZE + 1} đến{" "}
{Math.min(page * PAGE_SIZE, total)} của {total} ảnh
</div>
<Pagination
page={page}
pageCount={totalPages}
onChangePage={setPage}
/>
</div>
) : null}
</AdminTableLayout>
<MediaFormDialog
open={dialogOpen}
initial={editTarget}
saving={saving}
onOpenChange={setDialogOpen}
onSave={handleSave}
/>
......@@ -513,7 +476,7 @@ export default function AdminMediaPage() {
title="Xóa ảnh"
description={
<>
Bạn có chắc muốn xóa ảnh <span className="font-semibold">{deleteTarget?.name}</span>?
Bạn có chắc muốn xóa ảnh <span className="font-semibold">{deleteTarget?.original}</span>?
</>
}
onOpenChange={(open) => !open && setDeleteTarget(null)}
......
......@@ -243,7 +243,7 @@ export default function AdminNewsPage() {
const parsedPage = Number(searchParams.get("page") ?? 1);
return Number.isFinite(parsedPage) && parsedPage > 0 ? Math.floor(parsedPage) : 1;
});
const [pageSize] = React.useState(20);
const [pageSize] = React.useState(10);
const [total, setTotal] = React.useState(0);
const [publishedTotal, setPublishedTotal] = React.useState(0);
const [featuredTotal, setFeaturedTotal] = React.useState(0);
......@@ -295,17 +295,7 @@ export default function AdminNewsPage() {
});
}, []);
const loadStats = React.useCallback(async () => {
const [nextPublishedTotal, nextFeaturedTotal] = await Promise.all([
fetchCmsPostCount("status==published"),
fetchCmsPostCount("is_featured==true"),
]);
setPublishedTotal(nextPublishedTotal);
setFeaturedTotal(nextFeaturedTotal);
}, []);
const apiFilters = React.useMemo(() => {
const baseFilterParts = React.useMemo(() => {
const filters: string[] = [];
const keyword = debouncedSearch.trim();
......@@ -323,14 +313,42 @@ export default function AdminNewsPage() {
filters.push("type==page");
}
return filters;
}, [categoryFilter, debouncedSearch, typeFilter]);
const statusFilterParts = React.useMemo(() => {
if (statusFilter === "visible") {
filters.push("is_hidden==false");
} else if (statusFilter === "hidden") {
filters.push("is_hidden==true");
return ["is_hidden==false"];
}
if (statusFilter === "hidden") {
return ["is_hidden==true"];
}
return filters.join(",");
}, [categoryFilter, debouncedSearch, statusFilter, typeFilter]);
return [];
}, [statusFilter]);
const apiFilters = React.useMemo(() => {
return [...baseFilterParts, ...statusFilterParts].join(",");
}, [baseFilterParts, statusFilterParts]);
const visibleStatsFilters = React.useMemo(() => {
return [...baseFilterParts, ...statusFilterParts, "is_hidden==false"].join(",");
}, [baseFilterParts, statusFilterParts]);
const featuredStatsFilters = React.useMemo(() => {
return [...baseFilterParts, ...statusFilterParts, "is_featured==true"].join(",");
}, [baseFilterParts, statusFilterParts]);
const loadStats = React.useCallback(async () => {
const [nextPublishedTotal, nextFeaturedTotal] = await Promise.all([
fetchCmsPostCount(visibleStatsFilters),
fetchCmsPostCount(featuredStatsFilters),
]);
setPublishedTotal(nextPublishedTotal);
setFeaturedTotal(nextFeaturedTotal);
}, [featuredStatsFilters, visibleStatsFilters]);
const load = React.useCallback(async () => {
setReady(false);
......
......@@ -2,11 +2,12 @@
import * as React from "react";
import dayjs from "dayjs";
import { ChevronLeft, ChevronRight, Hash, Plus, Tag } from "lucide-react";
import { Hash, Plus, Tag } from "lucide-react";
import { toast } from "sonner";
import { AdminDeleteDialog } from "@/components/admin/admin-delete-dialog";
import { AdminRowActions } from "@/components/admin/admin-row-actions";
import { AdminTableLayout } from "@/components/admin/admin-table-layout";
import { Pagination } from "@/components/base/pagination";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
......@@ -41,6 +42,8 @@ interface TagFormValues {
slug: string;
}
const PAGE_SIZE = 10;
const EMPTY_FORM: TagFormValues = {
name: "",
slug: "",
......@@ -70,41 +73,38 @@ export default function AdminTagsPage() {
const [formValues, setFormValues] = React.useState<TagFormValues>(EMPTY_FORM);
const [deleteTarget, setDeleteTarget] = React.useState<CmsTagItem | null>(null);
const [page, setPage] = React.useState(1);
const [pageSize] = React.useState(10);
const [total, setTotal] = React.useState(0);
const load = React.useCallback(async () => {
setIsReady(false);
const result = await fetchCmsTagsPage({ page, pageSize });
const keyword = search.trim();
const result = await fetchCmsTagsPage({
page,
pageSize: PAGE_SIZE,
filters: keyword ? `name@=${keyword}|slug@=${keyword}` : undefined,
});
setItems(result.items);
setTotal(result.total);
setIsReady(true);
}, [page, pageSize]);
}, [page, search]);
React.useEffect(() => {
void load().catch((error) => {
toast.error(error instanceof Error ? error.message : "Không thể tải danh sách tag");
setItems([]);
setTotal(0);
setIsReady(true);
});
}, [load]);
const filteredItems = React.useMemo(() => {
const keyword = search.trim().toLowerCase();
if (!keyword) return items;
return items.filter(
(item) =>
item.name.toLowerCase().includes(keyword) ||
item.slug.toLowerCase().includes(keyword),
);
}, [items, search]);
const totalPages = Math.ceil(total / pageSize);
React.useEffect(() => {
setPage((currentPage) => (currentPage === 1 ? currentPage : 1));
setPage(1);
}, [search]);
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE));
const handlePageChange = (newPage: number) => {
if (newPage >= 1 && newPage <= totalPages) {
setPage(newPage);
......@@ -229,24 +229,26 @@ export default function AdminTagsPage() {
))}
</TableRow>
))
) : filteredItems.length === 0 ? (
) : items.length === 0 ? (
<TableRow>
<TableCell colSpan={5} className="py-14 text-center text-gray-700">
Không có tag nào phù hợp.
</TableCell>
</TableRow>
) : (
filteredItems.map((item) => (
items.map((item) => (
<TableRow key={item.id} className="hover:bg-[#063e8e]/[0.03]">
<TableCell className="px-4 py-4">
<Badge
variant="outline"
className="rounded-full border-[#063e8e]/20 bg-[#063e8e]/[0.04] px-3 py-1 text-[#063e8e]"
>
<Tag className="mr-1.5 h-3.5 w-3.5" />
{item.name}
</Badge>
</TableCell>
<TableCell className="px-4 py-4 font-mono text-sm text-gray-700">
<Hash className="mr-1 inline h-3.5 w-3.5 text-[#063e8e]" />
{item.slug}
</TableCell>
<TableCell className="px-4 py-4 text-center text-gray-700">
......@@ -269,64 +271,19 @@ export default function AdminTagsPage() {
</TableBody>
</Table>
{totalPages > 1 && (
<div className="flex items-center justify-between border-t border-[#063e8e]/10 px-4 py-3">
{totalPages > 1 ? (
<div className="flex flex-col gap-3 border-t border-[#063e8e]/10 px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
<div className="text-sm text-gray-700">
Hiển thị {(page - 1) * pageSize + 1} đến{" "}
{Math.min(page * pageSize, total)} của {total} tag
</div>
<div className="flex items-center gap-2">
<Button
variant="outline"
size="icon"
className="h-8 w-8 border-[#063e8e]/15 bg-white text-[#063e8e] hover:bg-[#063e8e]/10"
onClick={() => handlePageChange(page - 1)}
disabled={page === 1}
>
<ChevronLeft className="h-4 w-4" />
</Button>
<div className="flex items-center gap-1">
{Array.from({ length: Math.min(totalPages, 5) }, (_, index) => {
let pageNum;
if (totalPages <= 5) {
pageNum = index + 1;
} else if (page <= 3) {
pageNum = index + 1;
} else if (page >= totalPages - 2) {
pageNum = totalPages - 4 + index;
} else {
pageNum = page - 2 + index;
}
return (
<Button
key={pageNum}
variant={page === pageNum ? "default" : "outline"}
size="icon"
className={
page === pageNum
? "h-8 w-8 bg-[#063e8e] text-white hover:bg-[#063e8e]/90"
: "h-8 w-8 border-[#063e8e]/15 bg-white text-[#063e8e] hover:bg-[#063e8e]/10"
}
onClick={() => handlePageChange(pageNum)}
>
{pageNum}
</Button>
);
})}
</div>
<Button
variant="outline"
size="icon"
className="h-8 w-8 border-[#063e8e]/15 bg-white text-[#063e8e] hover:bg-[#063e8e]/10"
onClick={() => handlePageChange(page + 1)}
disabled={page === totalPages}
>
<ChevronRight className="h-4 w-4" />
</Button>
Hiển thị {(page - 1) * PAGE_SIZE + 1} đến{" "}
{Math.min(page * PAGE_SIZE, total)} của {total} tag
</div>
<Pagination
page={page}
pageCount={totalPages}
onChangePage={handlePageChange}
/>
</div>
)}
) : null}
</AdminTableLayout>
<Dialog open={formOpen} onOpenChange={setFormOpen}>
......
......@@ -7,6 +7,7 @@ import { toast } from "sonner";
import { AdminDeleteDialog } from "@/components/admin/admin-delete-dialog";
import { AdminRowActions } from "@/components/admin/admin-row-actions";
import { AdminTableLayout } from "@/components/admin/admin-table-layout";
import { Pagination } from "@/components/base/pagination";
import { Button } from "@/components/ui/button";
import {
Dialog,
......@@ -25,25 +26,45 @@ import {
TableRow,
} from "@/components/ui/table";
import {
createVideoId,
EMPTY_VIDEO_FORM,
type VideoFormValues,
type VideoItem,
persistVideos,
readVideos,
} from "@/mockdata/videos";
deleteVideoId,
getVideo,
patchVideoId,
postVideo,
} from "@/api/endpoints/video";
import type { Video as CmsVideoItem } from "@/api/models/video";
import { readVideoPageData, readVideoRows } from "@/lib/api/videos";
const PAGE_SIZE = 10;
const fieldClassName =
"rounded-xl border-[#063e8e]/15 bg-white text-gray-700 placeholder:text-gray-700 focus-visible:ring-[#063e8e]/30";
interface VideoFormValues {
id?: string;
name: string;
url: string;
}
const EMPTY_VIDEO_FORM: VideoFormValues = {
name: "",
url: "",
};
interface VideoFormDialogProps {
open: boolean;
initial: VideoItem | null;
initial: CmsVideoItem | null;
saving: boolean;
onOpenChange: (open: boolean) => void;
onSave: (data: VideoFormValues) => void;
onSave: (data: VideoFormValues) => Promise<void>;
}
function VideoFormDialog({ open, initial, onOpenChange, onSave }: VideoFormDialogProps) {
function VideoFormDialog({
open,
initial,
saving,
onOpenChange,
onSave,
}: VideoFormDialogProps) {
const [form, setForm] = React.useState<VideoFormValues>(EMPTY_VIDEO_FORM);
React.useEffect(() => {
......@@ -60,11 +81,14 @@ function VideoFormDialog({ open, initial, onOpenChange, onSave }: VideoFormDialo
);
}, [initial, open]);
const handleField = <K extends keyof VideoFormValues>(key: K, value: VideoFormValues[K]) => {
const handleField = <K extends keyof VideoFormValues>(
key: K,
value: VideoFormValues[K],
) => {
setForm((previous) => ({ ...previous, [key]: value }));
};
const handleSave = () => {
const handleSave = async () => {
if (!form.name.trim()) {
toast.error("Vui lòng nhập tên video");
return;
......@@ -75,7 +99,7 @@ function VideoFormDialog({ open, initial, onOpenChange, onSave }: VideoFormDialo
return;
}
onSave({
await onSave({
id: form.id,
name: form.name.trim(),
url: form.url.trim(),
......@@ -122,6 +146,7 @@ function VideoFormDialog({ open, initial, onOpenChange, onSave }: VideoFormDialo
variant="outline"
className="border-[#063e8e]/15 text-gray-700"
onClick={() => onOpenChange(false)}
disabled={saving}
>
<X className="mr-2 h-4 w-4" />
Hủy
......@@ -130,6 +155,7 @@ function VideoFormDialog({ open, initial, onOpenChange, onSave }: VideoFormDialo
type="button"
className="bg-[#063e8e] text-white hover:bg-[#063e8e]/90"
onClick={handleSave}
disabled={saving}
>
<Save className="mr-2 h-4 w-4" />
Lưu
......@@ -142,69 +168,93 @@ function VideoFormDialog({ open, initial, onOpenChange, onSave }: VideoFormDialo
}
export default function AdminVideosPage() {
const [items, setItems] = React.useState<VideoItem[]>([]);
const [items, setItems] = React.useState<CmsVideoItem[]>([]);
const [search, setSearch] = React.useState("");
const [ready, setReady] = React.useState(false);
const [saving, setSaving] = React.useState(false);
const [dialogOpen, setDialogOpen] = React.useState(false);
const [editTarget, setEditTarget] = React.useState<VideoItem | null>(null);
const [deleteTarget, setDeleteTarget] = React.useState<VideoItem | null>(null);
const [editTarget, setEditTarget] = React.useState<CmsVideoItem | null>(null);
const [deleteTarget, setDeleteTarget] = React.useState<CmsVideoItem | null>(null);
const [page, setPage] = React.useState(1);
const [total, setTotal] = React.useState(0);
React.useEffect(() => {
setItems(readVideos());
const loadVideos = React.useCallback(async () => {
setReady(false);
try {
const keyword = search.trim();
const response = await getVideo({
page,
pageSize: PAGE_SIZE,
sortField: "created_at",
sortOrder: "desc",
filters: keyword ? `name@=${keyword}|url@=${keyword}` : undefined,
});
const pageData = readVideoPageData(response);
setItems(readVideoRows(response));
setTotal(pageData.count ?? 0);
} catch (error) {
toast.error(error instanceof Error ? error.message : "Không thể tải danh sách video");
setItems([]);
setTotal(0);
} finally {
setReady(true);
}, []);
}
}, [page, search]);
const filtered = React.useMemo(() => {
const keyword = search.trim().toLowerCase();
if (!keyword) return items;
React.useEffect(() => {
void loadVideos();
}, [loadVideos]);
return items.filter(
(item) =>
item.name.toLowerCase().includes(keyword) || item.url.toLowerCase().includes(keyword),
);
}, [items, search]);
React.useEffect(() => {
setPage(1);
}, [search]);
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE));
const openCreate = () => {
setEditTarget(null);
setDialogOpen(true);
};
const openEdit = (item: VideoItem) => {
const openEdit = (item: CmsVideoItem) => {
setEditTarget(item);
setDialogOpen(true);
};
const handleSave = (data: VideoFormValues) => {
let next: VideoItem[];
const handleSave = async (data: VideoFormValues) => {
setSaving(true);
try {
if (data.id) {
next = items.map((item) => (item.id === data.id ? { ...item, ...data, id: data.id } : item));
await patchVideoId(data.id, { name: data.name, url: data.url });
toast.success("Đã cập nhật video");
} else {
next = [
...items,
{
id: createVideoId(),
name: data.name,
url: data.url,
},
];
await postVideo({ name: data.name, url: data.url });
toast.success("Đã thêm video mới");
}
setItems(next);
persistVideos(next);
setDialogOpen(false);
await loadVideos();
} catch (error) {
toast.error(error instanceof Error ? error.message : "Không thể lưu video");
} finally {
setSaving(false);
}
};
const handleDelete = () => {
const handleDelete = async () => {
if (!deleteTarget) return;
const next = items.filter((item) => item.id !== deleteTarget.id);
setItems(next);
persistVideos(next);
try {
await deleteVideoId(deleteTarget.id);
toast.success("Đã xóa video");
setDeleteTarget(null);
await loadVideos();
} catch (error) {
toast.error(error instanceof Error ? error.message : "Không thể xóa video");
}
};
return (
......@@ -216,7 +266,7 @@ export default function AdminVideosPage() {
actionIcon={<Plus className="mr-2 h-4 w-4" />}
actionMeta={
<div className="rounded-xl border border-[#063e8e]/15 bg-[#f8fbff] px-4 py-2 text-sm font-semibold text-[#163b73]">
Tổng số video: {items.length}
Tổng số video: {total}
</div>
}
onSearchChange={setSearch}
......@@ -240,20 +290,20 @@ export default function AdminVideosPage() {
</TableCell>
</TableRow>
))
) : filtered.length === 0 ? (
) : items.length === 0 ? (
<TableRow>
<TableCell colSpan={4} className="py-16 text-center text-gray-400">
Không có video nào
</TableCell>
</TableRow>
) : (
filtered.map((item, index) => (
items.map((item, index) => (
<TableRow
key={item.id}
className={index % 2 === 0 ? "bg-white" : "bg-[#063e8e]/3"}
>
<TableCell className="py-3 text-center text-sm text-gray-500">
{index + 1}
{(page - 1) * PAGE_SIZE + index + 1}
</TableCell>
<TableCell className="py-3 text-sm font-medium text-gray-800">
<div className="flex items-center gap-3">
......@@ -286,11 +336,26 @@ export default function AdminVideosPage() {
)}
</TableBody>
</Table>
{totalPages > 1 ? (
<div className="flex flex-col gap-3 border-t border-[#063e8e]/10 px-4 py-3 sm:flex-row sm:items-center sm:justify-between">
<div className="text-sm text-gray-700">
Hiển thị {(page - 1) * PAGE_SIZE + 1} đến{" "}
{Math.min(page * PAGE_SIZE, total)} của {total} video
</div>
<Pagination
page={page}
pageCount={totalPages}
onChangePage={setPage}
/>
</div>
) : null}
</AdminTableLayout>
<VideoFormDialog
open={dialogOpen}
initial={editTarget}
saving={saving}
onOpenChange={setDialogOpen}
onSave={handleSave}
/>
......
......@@ -2,6 +2,7 @@
import * as React from "react";
import { ImagePlus, Search, Upload, X } from "lucide-react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import {
......@@ -12,14 +13,17 @@ import {
DialogTitle,
} from "@/components/ui/dialog";
import { SafeNextImage } from "@/components/admin/safe-next-image";
import type { AdminMediaItem } from "@/mockdata/admin-news";
import {
AdminMediaItem,
createAdminMediaId,
persistAdminMediaItems,
readAdminMediaItems,
} from "@/mockdata/admin-news";
fetchCmsFiles,
toAdminMediaItem,
uploadCmsFile,
} from "@/lib/api/files";
import { Pagination } from "@/components/base/pagination";
import { cn } from "@/lib/utils";
const PAGE_SIZE = 10;
interface AdminImagePickerProps {
open: boolean;
selectedId?: string | null;
......@@ -43,52 +47,71 @@ export function AdminImagePicker({
const inputRef = React.useRef<HTMLInputElement | null>(null);
const [search, setSearch] = React.useState("");
const [items, setItems] = React.useState<AdminMediaItem[]>([]);
const [page, setPage] = React.useState(1);
const [total, setTotal] = React.useState(0);
const [ready, setReady] = React.useState(false);
const [uploading, setUploading] = React.useState(false);
React.useEffect(() => {
const load = React.useCallback(async () => {
if (!open) return;
setItems(readAdminMediaItems());
}, [open]);
const visibleItems = React.useMemo(() => {
const keyword = search.trim().toLowerCase();
if (!keyword) return items;
setReady(false);
return items.filter((item) => {
return (
item.name.toLowerCase().includes(keyword) ||
item.alt.toLowerCase().includes(keyword) ||
item.url.toLowerCase().includes(keyword)
);
try {
const result = await fetchCmsFiles({
page,
pageSize: PAGE_SIZE,
search,
});
}, [items, search]);
setItems(result.rows.map(toAdminMediaItem));
setTotal(result.count);
} catch (error) {
toast.error(error instanceof Error ? error.message : "Không thể tải thư viện hình ảnh");
setItems([]);
setTotal(0);
} finally {
setReady(true);
}
}, [open, page, search]);
React.useEffect(() => {
void load();
}, [load]);
React.useEffect(() => {
if (!open) return;
setPage(1);
}, [open, search]);
const totalPages = Math.max(1, Math.ceil(total / PAGE_SIZE));
const handleUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0];
if (!file) return;
const reader = new FileReader();
reader.onload = () => {
const nextItem: AdminMediaItem = {
id: createAdminMediaId(),
name: file.name,
alt: file.name.replace(/\.[^.]+$/, ""),
url: typeof reader.result === "string" ? reader.result : "/img-error.png",
mime: file.type || "image/*",
size: file.size,
created_at: new Date().toISOString(),
updated_at: new Date().toISOString(),
source: "upload",
};
setUploading(true);
try {
const uploaded = await uploadCmsFile({
file,
original: file.name,
});
if (!uploaded) {
throw new Error("Không thể tải hình ảnh lên");
}
const nextItems = [nextItem, ...items];
setItems(nextItems);
persistAdminMediaItems(nextItems);
const nextItem = toAdminMediaItem(uploaded);
toast.success("Đã tải hình ảnh lên");
onSelect(nextItem);
onOpenChange(false);
};
reader.readAsDataURL(file);
} catch (error) {
toast.error(error instanceof Error ? error.message : "Không thể tải hình ảnh lên");
} finally {
setUploading(false);
event.target.value = "";
}
};
return (
......@@ -101,7 +124,7 @@ export function AdminImagePicker({
Thư viện hình ảnh
</DialogTitle>
<DialogDescription className="mt-1 text-sm text-gray-700">
Chọn ảnh có sẵn hoặc tải thêm ảnh mới cho bài viết.
Chọn ảnh từ API /file hoặc tải thêm ảnh mới cho bài viết.
</DialogDescription>
</div>
</div>
......@@ -130,25 +153,41 @@ export function AdminImagePicker({
type="button"
onClick={() => inputRef.current?.click()}
className="bg-[#063e8e] text-white hover:bg-[#063e8e]/90"
disabled={uploading}
>
<Upload className="mr-2 h-4 w-4" />
Tải hình ảnh
{uploading ? "Đang tải..." : "Tải hình ảnh"}
</Button>
</div>
</div>
<div className="max-h-[60vh] overflow-y-auto px-6 py-6">
{visibleItems.length === 0 ? (
{!ready ? (
<div className="grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-5">
{Array.from({ length: PAGE_SIZE }).map((_, index) => (
<div
key={`image-picker-loading-${index}`}
className="overflow-hidden rounded-2xl border border-[#063e8e]/10 bg-white"
>
<div className="aspect-[4/3] animate-pulse bg-[#063e8e]/10" />
<div className="space-y-2 p-4">
<div className="h-4 animate-pulse rounded bg-[#063e8e]/10" />
<div className="h-3 w-1/2 animate-pulse rounded bg-[#063e8e]/10" />
</div>
</div>
))}
</div>
) : items.length === 0 ? (
<div className="flex min-h-[240px] flex-col items-center justify-center rounded-2xl border border-dashed border-[#063e8e]/15 bg-[#063e8e]/[0.03] px-6 text-center">
<ImagePlus className="mb-3 h-10 w-10 text-[#063e8e]" />
<p className="text-base font-medium text-black">Chưa có hình ảnh phù hợp</p>
<p className="mt-1 text-sm text-gray-700">
H?y th? t? kh?a kh?c ho?c t?i th?m h?nh ?nh v?o thu vi?n.
Hãy thử từ khóa khác hoặc tải thêm hình ảnh vào thư viện.
</p>
</div>
) : (
<div className="grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-4">
{visibleItems.map((item) => (
<div className="grid grid-cols-2 gap-4 md:grid-cols-3 xl:grid-cols-5">
{items.map((item) => (
<button
key={item.id}
type="button"
......@@ -172,7 +211,7 @@ export function AdminImagePicker({
/>
{item.id === selectedId ? (
<div className="absolute right-3 top-3 rounded-full bg-[#063e8e] px-2 py-1 text-xs font-medium text-white">
?? ch?n
Đã chọn
</div>
) : null}
</div>
......@@ -180,7 +219,7 @@ export function AdminImagePicker({
<p className="line-clamp-1 text-sm font-medium text-black">{item.name}</p>
<div className="flex items-center justify-between gap-2 text-xs text-gray-700">
<span>{formatFileSize(item.size)}</span>
<span>{item.source === "upload" ? "Tải lên" : "Hệ thống"}</span>
<span>Tải lên</span>
</div>
</div>
</button>
......@@ -189,6 +228,16 @@ export function AdminImagePicker({
)}
</div>
{totalPages > 1 ? (
<div className="flex flex-col gap-3 border-t border-[#063e8e]/10 px-6 py-4 sm:flex-row sm:items-center sm:justify-between">
<div className="text-sm text-gray-700">
Hiển thị {(page - 1) * PAGE_SIZE + 1} đến{" "}
{Math.min(page * PAGE_SIZE, total)} của {total} ảnh
</div>
<Pagination page={page} pageCount={totalPages} onChangePage={setPage} />
</div>
) : null}
<div className="flex justify-end border-t border-[#063e8e]/10 px-6 py-4">
<Button
type="button"
......
......@@ -409,11 +409,17 @@ export function AdminNewsForm({
setForm(isCreate ? cloneAdminNewsFormValues() : null);
try {
const [{ items: nextNewsItems }, nextHeaderConfig, nextTags] = await Promise.all([
fetchCmsNewsItems(),
const [nextHeaderConfig, nextTags] = await Promise.all([
fetchHeaderConfigItems(),
fetchCmsTags(),
]);
const nextNewsItems = isCreate
? []
: (await fetchCmsNewsItems({
page: 1,
pageSize: 10,
filters: newsId ? `id==${newsId}` : undefined,
})).items;
if (cancelled) return;
......
......@@ -369,7 +369,7 @@ const transformPost = (
async function fetchAllTagsInternal() {
const result = await cmsRequest<CmsPagedResult<CmsTagItem>>(
"/tag?page=1&pageSize=200&sortField=name&sortOrder=ASC",
"/tag?page=1&pageSize=10&sortField=name&sortOrder=ASC",
);
return result.rows ?? [];
}
......@@ -541,6 +541,7 @@ export async function fetchCmsTags() {
export async function fetchCmsTagsPage(params?: {
page?: number;
pageSize?: number;
filters?: string;
}) {
const searchParams = new URLSearchParams({
page: String(params?.page ?? 1),
......@@ -549,6 +550,10 @@ export async function fetchCmsTagsPage(params?: {
sortOrder: "ASC",
});
if (params?.filters?.trim()) {
searchParams.set("filters", params.filters.trim());
}
const result = await cmsRequest<CmsPagedResult<CmsTagItem>>(
`/tag?${searchParams.toString()}`,
);
......@@ -738,7 +743,7 @@ export async function fetchCmsNewsItems(params?: {
}) {
const queryParams = new URLSearchParams({
page: String(params?.page ?? 1),
pageSize: String(params?.pageSize ?? 20),
pageSize: String(params?.pageSize ?? 10),
sortField: params?.sortField ?? "created_at",
sortOrder: params?.sortOrder ?? "desc",
});
......@@ -757,7 +762,7 @@ export async function fetchCmsNewsItems(params?: {
items: rows.map((item) => transformPost(item)),
total: result.count ?? 0,
page: result.page ?? 1,
pageSize: result.pageSize ?? 20,
pageSize: result.pageSize ?? 10,
};
}
......
"use client";
import { useCustomClient } from "@/api/mutator/custom-client";
import Links from "@/links";
import type { AdminMediaItem } from "@/mockdata/admin-news";
export type CmsFileItem = {
id: string;
path: string;
original: string;
mime: string;
created_at?: string | null;
status?: string | null;
};
export type CmsFileListResult = {
rows: CmsFileItem[];
count: number;
page: number;
pageSize: number;
totalPages: number;
};
type FileEnvelope<T> = {
responseData?: T;
data?: {
responseData?: T;
};
};
type FilePageData = {
rows?: CmsFileItem[];
count?: number;
page?: number;
pageSize?: number;
};
const readFilePageData = (payload: unknown): FilePageData => {
const root = payload as FileEnvelope<FilePageData>;
return root.responseData ?? root.data?.responseData ?? {};
};
export const resolveCmsFileUrl = (path?: string | null) => {
const value = path?.trim();
if (!value) return "/img-error.png";
if (value.startsWith("http://") || value.startsWith("https://")) return value;
if (value.startsWith("/")) return `${Links.imageEndpoint.replace(/\/+$/, "")}${value}`;
return `${Links.imageEndpoint}${value.replace(/^\/+/, "")}`;
};
export const toAdminMediaItem = (item: CmsFileItem): AdminMediaItem => ({
id: item.id,
name: item.original || item.path,
alt: item.original || item.path,
url: resolveCmsFileUrl(item.path),
mime: item.mime,
size: 0,
created_at: item.created_at ?? "",
updated_at: item.created_at ?? "",
source: "upload",
});
export async function fetchCmsFiles(params?: {
page?: number;
pageSize?: number;
search?: string;
}) {
const keyword = params?.search?.trim() ?? "";
const filters = [
"mime@=image",
keyword ? `original@=${keyword}|path@=${keyword}` : "",
].filter(Boolean).join(",");
const query = new URLSearchParams({
page: String(params?.page ?? 1),
pageSize: String(params?.pageSize ?? 10),
sortField: "created_at",
sortOrder: "desc",
filters,
});
const response = await useCustomClient<FileEnvelope<FilePageData>>(`/file?${query.toString()}`);
const pageData = readFilePageData(response);
const pageSize = pageData.pageSize ?? params?.pageSize ?? 10;
const count = pageData.count ?? 0;
return {
rows: pageData.rows ?? [],
count,
page: pageData.page ?? params?.page ?? 1,
pageSize,
totalPages: Math.max(1, Math.ceil(count / pageSize)),
} satisfies CmsFileListResult;
}
export async function uploadCmsFile(input: { file: File; original?: string }) {
const formData = new FormData();
formData.append("file", input.file);
if (input.original?.trim()) {
formData.append("original", input.original.trim());
}
const response = await useCustomClient<FileEnvelope<CmsFileItem>>("/file/upload", {
method: "POST",
body: formData,
});
const root = response as FileEnvelope<CmsFileItem>;
return root.responseData ?? root.data?.responseData ?? null;
}
export async function fetchCmsFileById(id: string) {
const response = await useCustomClient<FileEnvelope<CmsFileItem>>(`/file/${id}`);
const root = response as FileEnvelope<CmsFileItem>;
return root.responseData ?? root.data?.responseData ?? null;
}
export async function deleteCmsFile(id: string) {
await useCustomClient(`/file/${id}`, {
method: "DELETE",
});
}
"use client";
import {
deleteNewsletterSubscriptionId,
getNewsletterSubscription,
patchNewsletterSubscriptionId,
postNewsletterSubscription,
} from "@/api/endpoints/newsletter-subscription";
import type { NewsletterSubscription } from "@/api/models/newsletterSubscription";
export type ClientNewsletterSubscriptionListResult = {
rows: NewsletterSubscription[];
count: number;
page: number;
pageSize: number;
};
const readNewsletterPageData = (payload: unknown) => {
const root = payload as {
responseData?: { rows?: unknown[]; count?: number; page?: number; pageSize?: number };
data?: { responseData?: { rows?: unknown[]; count?: number; page?: number; pageSize?: number } };
};
return root.responseData ?? root.data?.responseData ?? {};
};
export async function fetchNewsletterSubscriptions(params?: {
page?: number;
pageSize?: number;
sortField?: string;
sortOrder?: "asc" | "desc";
filters?: string;
}) {
const response = await getNewsletterSubscription({
page: params?.page ?? 1,
pageSize: params?.pageSize ?? 10,
sortField: params?.sortField ?? "created_at",
sortOrder: params?.sortOrder ?? "desc",
filters: params?.filters,
});
const pageData = readNewsletterPageData(response);
return {
rows: (pageData.rows ?? []) as NewsletterSubscription[],
count: pageData.count ?? 0,
page: pageData.page ?? params?.page ?? 1,
pageSize: pageData.pageSize ?? params?.pageSize ?? 10,
} satisfies ClientNewsletterSubscriptionListResult;
}
export async function subscribeNewsletterEmail(email: string) {
return postNewsletterSubscription({ email: email.trim() });
}
export async function deleteNewsletterSubscription(id: string) {
return deleteNewsletterSubscriptionId(id);
}
export async function markNewsletterSubscriptionSeen(id: string) {
return patchNewsletterSubscriptionId(id, { is_seen: true });
}
"use client";
import { getVideo } from "@/api/endpoints/video";
import type { Video } from "@/api/models/video";
export type ClientVideoItem = Video & {
thumbnail: string;
watchUrl: string;
};
export type ClientVideoListResult = {
rows: ClientVideoItem[];
count: number;
page: number;
pageSize: number;
totalPages: number;
};
const FALLBACK_VIDEO_THUMBNAIL = "/img-error.png";
export const readVideoRows = (payload: unknown): Video[] => {
const root = payload as {
responseData?: { rows?: unknown[] };
data?: { responseData?: { rows?: unknown[] } };
};
const rows = root.responseData?.rows ?? root.data?.responseData?.rows ?? [];
return rows as Video[];
};
export const readVideoPageData = (payload: unknown) => {
const root = payload as {
responseData?: { rows?: unknown[]; count?: number; page?: number; pageSize?: number };
data?: { responseData?: { rows?: unknown[]; count?: number; page?: number; pageSize?: number } };
};
return root.responseData ?? root.data?.responseData ?? {};
};
export const getYoutubeVideoId = (url: string) => {
const value = url.trim();
if (!value) return "";
try {
const parsedUrl = new URL(value);
const host = parsedUrl.hostname.replace(/^www\./, "");
if (host === "youtu.be") {
return parsedUrl.pathname.split("/").filter(Boolean)[0] ?? "";
}
if (host.includes("youtube.com")) {
if (parsedUrl.pathname.startsWith("/embed/")) {
return parsedUrl.pathname.split("/").filter(Boolean)[1] ?? "";
}
return parsedUrl.searchParams.get("v") ?? "";
}
} catch {
return "";
}
return "";
};
export const getVideoThumbnail = (url: string) => {
const videoId = getYoutubeVideoId(url);
return videoId ? `https://img.youtube.com/vi/${videoId}/hqdefault.jpg` : FALLBACK_VIDEO_THUMBNAIL;
};
export const normalizeVideoUrl = (url: string) => {
const value = url.trim();
const videoId = getYoutubeVideoId(value);
if (videoId) {
return `https://www.youtube.com/watch?v=${videoId}`;
}
return value;
};
export async function fetchClientVideos(params?: { page?: number; pageSize?: number }) {
const response = await getVideo({
page: params?.page ?? 1,
pageSize: params?.pageSize ?? 10,
sortField: "created_at",
sortOrder: "desc",
});
const pageData = readVideoPageData(response);
const pageSize = pageData.pageSize ?? params?.pageSize ?? 10;
const count = pageData.count ?? 0;
return {
rows: readVideoRows(response).map((item) => ({
...item,
thumbnail: getVideoThumbnail(item.url),
watchUrl: normalizeVideoUrl(item.url),
})),
count,
page: pageData.page ?? params?.page ?? 1,
pageSize,
totalPages: Math.max(1, Math.ceil(count / pageSize)),
} satisfies ClientVideoListResult;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment