This repository has been archived by the owner on Oct 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
173 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
export { Dashboard } from './Dashboard'; | ||
export { default as Dashboard } from './Dashboard'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { useSlectedDateStore } from './useSlectedDateStore'; | ||
export { useSelectCityStore } from './useSelectCityStore'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { useSelectCityStore } from './useSelectCityStore'; |
27 changes: 27 additions & 0 deletions
27
domains/dashboard/store/useSelectCityStore/useSelectCityStore.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { create } from 'zustand'; | ||
|
||
interface City { | ||
city: string; | ||
cityCode: string; | ||
} | ||
|
||
interface SelectedCityStore { | ||
city: string; | ||
cityCode: string; | ||
setSelectedCity: ({ city, cityCode }: City) => void; | ||
getSelectedCity: () => { city: string; cityCode: string }; | ||
} | ||
|
||
const useSelectCityStore = create<SelectedCityStore>((set, get) => ({ | ||
city: '', | ||
cityCode: '', | ||
setSelectedCity: ({ city, cityCode }) => { | ||
set({ city, cityCode }); | ||
}, | ||
getSelectedCity: () => { | ||
const { city, cityCode } = get(); | ||
return { city, cityCode }; | ||
}, | ||
})); | ||
|
||
export { useSelectCityStore }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { gql } from '@apollo/client'; | ||
|
||
export const cities = gql` | ||
query cities { | ||
cities { | ||
name | ||
code | ||
} | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { symptomsQuery } from './symptomsQuery'; | ||
export { clinicalDataQuery } from './clinicalDataQuery'; | ||
export { cities } from './cities'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import { DatePicker as HeaderDatePicker } from '@/shared/components/DatePicker'; | ||
import { HeaderRoot } from './Header'; | ||
import HeaderIcon from './Icon'; | ||
import { SelectCity } from '@/shared/components/SelectCity'; | ||
|
||
export const Header = { | ||
Root: HeaderRoot, | ||
DatePicker: HeaderDatePicker, | ||
Icon: HeaderIcon, | ||
City: SelectCity, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { cities } from '@/services/graphql/query'; | ||
import { useQuery } from '@apollo/client'; | ||
import { Select } from 'antd'; | ||
import { type ComponentProps, type FC } from 'react'; | ||
import { useSelectCityStore } from '@/domains/dashboard/store'; | ||
|
||
interface Props extends ComponentProps<typeof Select> {} | ||
|
||
interface City { | ||
name: string; | ||
code: string; | ||
} | ||
|
||
interface Data { | ||
cities: City[]; | ||
} | ||
|
||
const SelectCity: FC<Props> = (props) => { | ||
const { data, error } = useQuery<Data>(cities); | ||
const { setSelectedCity } = useSelectCityStore(); | ||
|
||
const handleSelectCity = (value: unknown, label: string): void => { | ||
// eslint-disable-next-line no-extra-boolean-cast | ||
if (Boolean(value)) { | ||
setSelectedCity({ city: label, cityCode: String(value) }); | ||
} | ||
}; | ||
|
||
if (error != null || data == null) { | ||
return; | ||
} | ||
|
||
const refined = data.cities.map((city) => ({ | ||
label: city.name, | ||
value: city.code, | ||
})); | ||
|
||
return ( | ||
<Select | ||
showSearch | ||
className='mr-3' | ||
style={{ width: 200 }} | ||
placeholder='Pesquise uma cidade' | ||
optionFilterProp='children' | ||
onSelect={(value: string | unknown, { label }) => { | ||
handleSelectCity(value, label); | ||
}} | ||
filterOption={(input, option) => (option?.label ?? '').includes(input)} | ||
filterSort={(optionA, optionB) => | ||
(optionA?.label ?? '').toLowerCase().localeCompare((optionB?.label ?? '').toLowerCase()) | ||
} | ||
options={refined} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export { SelectCity }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { SelectCity } from './SelectCity'; |