Skip to content

Commit

Permalink
Foi desenvolvido o carregamento da disponibilidade de um dia, sempre …
Browse files Browse the repository at this point in the history
…que o usuario selecionar uma nova data, foi usado o useEffect para trazer os dados da api e utilizado o setAvailability para salvar essas informações.
  • Loading branch information
NecroKills committed Jun 12, 2020
1 parent cf03289 commit 92fc547
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/pages/CreateAppointment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface Provider {
avatar_url: string;
}

interface AvailabilityItem {
hour: number;
available: boolean;
}

const CreateAppointment: React.FC = () => {
const route = useRoute();
const routeParams = route.params as RouteParams;
Expand All @@ -45,6 +50,7 @@ const CreateAppointment: React.FC = () => {
);
const [showDatePicker, setShowDatePicker] = useState(false);
const [selectedDate, setSelectedDate] = useState(new Date());
const [availability, setAvailability] = useState<AvailabilityItem[]>([]);

useEffect(() => {
api.get('providers').then(response => {
Expand Down Expand Up @@ -74,6 +80,20 @@ const CreateAppointment: React.FC = () => {
}
}, []);

useEffect(() => {
api
.get(`/providers/${selectedProvider}/day-availability`, {
params: {
day: selectedDate.getDate(),
month: selectedDate.getMonth() + 1,
year: selectedDate.getFullYear(),
},
})
.then(response => {
setAvailability(response.data);
});
}, [selectedDate, selectedProvider]);

return (
<Container>
<Header>
Expand Down

0 comments on commit 92fc547

Please sign in to comment.