parent
7dcca6a4f4
commit
ad6d2f27e2
@ -1,22 +1,8 @@
|
||||
import type { FilterChoice } from '~/components/questions/filter/FilterSection';
|
||||
|
||||
import { trpc } from '../trpc';
|
||||
import useCompanyOptions from '../shared/useCompanyOptions';
|
||||
|
||||
export default function useDefaultCompany(): FilterChoice | undefined {
|
||||
const { data: companies } = trpc.useQuery([
|
||||
'companies.list',
|
||||
{
|
||||
name: '',
|
||||
},
|
||||
]);
|
||||
|
||||
const company = companies?.[0];
|
||||
if (company === undefined) {
|
||||
return company;
|
||||
}
|
||||
return {
|
||||
id: company.id,
|
||||
label: company.name,
|
||||
value: company.id,
|
||||
};
|
||||
const { data: companyOptions } = useCompanyOptions('google');
|
||||
return companyOptions[0];
|
||||
}
|
||||
|
@ -1,31 +1,12 @@
|
||||
import type { FilterChoice } from '~/components/questions/filter/FilterSection';
|
||||
|
||||
import { trpc } from '../trpc';
|
||||
import useLocationOptions from './useLocationOptions';
|
||||
|
||||
import type { Location } from '~/types/questions';
|
||||
|
||||
export default function useDefaultLocation():
|
||||
| (FilterChoice & Location)
|
||||
| undefined {
|
||||
const { data: locations } = trpc.useQuery([
|
||||
'locations.cities.list',
|
||||
{
|
||||
name: 'singapore',
|
||||
},
|
||||
]);
|
||||
|
||||
if (locations === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const { id, name, state } = locations[0];
|
||||
|
||||
return {
|
||||
cityId: id,
|
||||
countryId: state.country.id,
|
||||
id,
|
||||
label: `${name}, ${state.name}, ${state.country.name}`,
|
||||
stateId: state.id,
|
||||
value: id,
|
||||
};
|
||||
const { data: locationOptions } = useLocationOptions('singapore');
|
||||
return locationOptions[0];
|
||||
}
|
||||
|
@ -0,0 +1,30 @@
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { trpc } from '../trpc';
|
||||
|
||||
export default function useLocationOptions(query: string) {
|
||||
const { data: locations, ...restQuery } = trpc.useQuery([
|
||||
'locations.cities.list',
|
||||
{
|
||||
name: query,
|
||||
},
|
||||
]);
|
||||
|
||||
const locationOptions = useMemo(() => {
|
||||
return (
|
||||
locations?.map(({ id, name, state }) => ({
|
||||
cityId: id,
|
||||
countryId: state.country.id,
|
||||
id,
|
||||
label: `${name}, ${state.name}, ${state.country.name}`,
|
||||
stateId: state.id,
|
||||
value: id,
|
||||
})) ?? []
|
||||
);
|
||||
}, [locations]);
|
||||
|
||||
return {
|
||||
data: locationOptions,
|
||||
...restQuery,
|
||||
};
|
||||
}
|
Loading…
Reference in new issue