Skip to content

Commit

Permalink
feat: add calendar google link
Browse files Browse the repository at this point in the history
  • Loading branch information
ialexanderbrito committed Apr 5, 2022
1 parent b36d147 commit f5a8367
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/contexts/User.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ export function UserProvider({ children }: any) {
return false;
}

function generateGoogleCalendarEvent(
title: string,
startDate: string,
endDate: string,
description?: string,
location?: string,
) {
const url = `https://calendar.google.com/calendar/render?action=TEMPLATE&text=${title}&dates=${startDate}/${endDate}&details=${description}&location=${location}`;
window.open(url, '_blank');
}

const dateFormattedCalendar = format(selectDay, 'yyyyMMdd');

const hourFormattedCalendar = selectHours.replace(':', '');
const hourFormattedCalendarEnd = Number(hourFormattedCalendar) + 100;

const startDate = dateFormattedCalendar + 'T' + hourFormattedCalendar;

const endDate = dateFormattedCalendar + 'T' + hourFormattedCalendarEnd;

async function buscarBarbeiros() {
const { data, error, status } = await getBarbeiros();

Expand Down Expand Up @@ -284,10 +304,8 @@ export function UserProvider({ children }: any) {
}, [clientId]);

useEffect(() => {
if (isBarbeiro) {
buscarClientes();
}
}, [barberId, selectDay, isBarbeiro]);
buscarClientes();
}, [barberId, selectDay]);

useEffect(() => {
const params = pathname.split('/')[1];
Expand Down Expand Up @@ -334,6 +352,9 @@ export function UserProvider({ children }: any) {
verificaDataEHoraSelecionada,
horariosAgendados,
buscarAgendamentosData,
generateGoogleCalendarEvent,
startDate,
endDate,
}}
>
{children}
Expand Down

0 comments on commit f5a8367

Please sign in to comment.