forked from VinokurovVE/tests
Reports: city autocomplete, mutation, refresh
This commit is contained in:
@ -99,17 +99,33 @@ export function useFileType(fileName?: string | null, file?: Blob | null) {
|
||||
}
|
||||
}
|
||||
|
||||
export function useReport(city_id?: number) {
|
||||
export function useReport(city_id?: number | null) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
city_id ? `/info/reports/${city_id}?to_export=false` : null,
|
||||
fetcher,
|
||||
(url) => fetcher(url, BASE_URL.info),
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
report: JSON.parse(data),
|
||||
report: data ? JSON.parse(data) : [],
|
||||
isLoading,
|
||||
isError: error
|
||||
}
|
||||
}
|
||||
|
||||
export function useReportExport(city_id?: number | null, to_export?: boolean) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
city_id && to_export ? `/info/reports/${city_id}?to_export=${to_export}` : null,
|
||||
(url) => fetcher(url, BASE_URL.info, 'blob'),
|
||||
{
|
||||
revalidateOnFocus: false
|
||||
}
|
||||
)
|
||||
|
||||
return {
|
||||
reportExported: data ? data : null,
|
||||
isLoading,
|
||||
isError: error
|
||||
}
|
||||
@ -150,7 +166,7 @@ export function useRegions(limit?: number, page?: number, search?: string | null
|
||||
}
|
||||
}
|
||||
|
||||
export function useCities(limit?: number, page?: number, search?: string) {
|
||||
export function useCities(limit?: number, page?: number, search?: string | null) {
|
||||
const { data, error, isLoading } = useSWR(
|
||||
`/general/cities?limit=${limit || 10}&page=${page || 1}${search ? `&search=${search}` : ''}`,
|
||||
(url) => fetcher(url, BASE_URL.fuel),
|
||||
|
Reference in New Issue
Block a user