Skip to content

Commit

Permalink
Merge pull request #20 from GabrielDVpereira/wpp-link
Browse files Browse the repository at this point in the history
Wpp link
  • Loading branch information
gabibguedes authored Dec 7, 2022
2 parents 6a5a676 + 821b54b commit dbf3470
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './alert'
export * from './parseEvents'
export * from './color'
export * from './parseBookingToZapLink'
export * from './updateApproval'
12 changes: 12 additions & 0 deletions src/helpers/parseBookingToZapLink.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Booking } from "_/models";

const ZAP_LINK = `https://api.whatsapp.com/send?phone=${process.env.REACT_APP_ZAP_NUMBER}`
export function parseBookingToZapLink(booking: Booking){
const baseMessage = `Oii! Posso pegar o carro dia ${
booking.date.toLocaleString()
} por ${booking.duration} hora${booking.duration > 1 ? 's' : ''}?
Confirma lá no NeteApp?
${process.env.REACT_APP_NETE_APP_LINK}`

return ZAP_LINK + `&text=${baseMessage.replace(' ', '%20')}`
}
8 changes: 6 additions & 2 deletions src/pages/Booking/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { useState } from "react";
import { useAuth, useBooking } from "_/contexts";
import { parseDateToLocaleString } from "_/util";
import { useNavigate } from "react-router-dom";
import { parseBookingToZapLink } from "_/helpers";
import { Booking as BookingModel} from "_/models";
import { ROUTE_PATHS, APPROVAL_STATE } from "_/constants";

export function Booking(){
Expand All @@ -24,9 +26,11 @@ export function Booking(){
bookerName: user.name,
approval: APPROVAL_STATE.pending
}

createBooking(bookingData)
return navigate(ROUTE_PATHS.home)

const link = parseBookingToZapLink(bookingData as BookingModel)
window.open(link, "_blank")
navigate(ROUTE_PATHS.home)
}
return (
<PageTemplate
Expand Down

0 comments on commit dbf3470

Please sign in to comment.