Skip to content

Commit

Permalink
Merge branch 'release'
Browse files Browse the repository at this point in the history
  • Loading branch information
aniku777tw committed Oct 12, 2023
2 parents 59e4f2d + deedaec commit 9f8b5f0
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 74 deletions.
4 changes: 2 additions & 2 deletions src/components/appointment/AppointmentCollectionTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export const AppointmentPlanCollection: React.FC<{
id: appointmentPlan.id,
defaultMeetGateway: appointmentPlan.defaultMeetGateway,
reservationType: appointmentPlan.rescheduleType,
reservationAmount: appointmentPlan.rescheduleAmount,
reservationAmount: appointmentPlan.reservationAmount,
capacity: appointmentPlan.capacity,
}}
appointmentPeriods={appointmentPlan.periods}
Expand Down Expand Up @@ -244,7 +244,7 @@ export const AppointmentPlanCollection: React.FC<{
id: appointmentPlan.id,
defaultMeetGateway: appointmentPlan.defaultMeetGateway,
reservationType: appointmentPlan.rescheduleType,
reservationAmount: appointmentPlan.rescheduleAmount,
reservationAmount: appointmentPlan.reservationAmount,
capacity: appointmentPlan.capacity,
}}
appointmentPeriods={appointmentPlan.periods}
Expand Down
8 changes: 6 additions & 2 deletions src/components/appointment/AppointmentPeriodCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ const AppointmentPeriodBlock: React.VFC<{
reservationAmount: number
capacity: number
}
services: { id: string; gateway: string }[]
loadingServices: boolean
onClick: (period: AppointmentPeriod) => void
}> = ({ periods, creatorId, appointmentPlan, onClick }) => {
}> = ({ periods, creatorId, appointmentPlan, services, loadingServices, onClick }) => {
const { setVisible: setAuthModalVisible } = useContext(AuthModalContext)
const { isAuthenticated } = useAuth()
const { loading: loadingServices, services } = useService()
const [overLapPeriods, setOverLapPeriods] = useState<string[]>([])

return (
Expand Down Expand Up @@ -102,6 +103,7 @@ const AppointmentPeriodCollection: React.VFC<{
appointmentPeriods: AppointmentPeriod[]
onClick: (period: AppointmentPeriod) => void
}> = ({ creatorId, appointmentPlan, appointmentPeriods, onClick }) => {
const { loading: loadingServices, services } = useService()
const periods = groupBy(
period => dayjs(period.startedAt).format('YYYY-MM-DD(dd)'),
appointmentPeriods.filter(v =>
Expand All @@ -120,6 +122,8 @@ const AppointmentPeriodCollection: React.VFC<{
creatorId={creatorId}
appointmentPlan={appointmentPlan}
onClick={onClick}
services={services}
loadingServices={loadingServices}
/>
))}
</>
Expand Down
117 changes: 59 additions & 58 deletions src/hooks/appointment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,47 +52,44 @@ export const useAppointmentPlanCollection = (memberId: string, startedAt: Date,

const appointmentPlans: (AppointmentPlan & {
periods: AppointmentPeriod[]
})[] =
loading || error || !data
? []
: data.appointment_plan.map(appointmentPlan => ({
id: appointmentPlan.id,
title: appointmentPlan.title,
description: appointmentPlan.description || '',
duration: appointmentPlan.duration,
price: appointmentPlan.price,
phone: null,
supportLocales: appointmentPlan.support_locales,
capacity: appointmentPlan.capacity,
defaultMeetGateway: appointmentPlan.default_meet_gateway,
meetGenerationMethod: appointmentPlan.meet_generation_method,
currency: {
id: appointmentPlan.currency.id,
label: appointmentPlan.currency.label,
unit: appointmentPlan.currency.unit,
name: appointmentPlan.currency.name,
},
rescheduleAmount: appointmentPlan.reschedule_amount,
rescheduleType: appointmentPlan.reschedule_type as ReservationType,
periods: appointmentPlan.appointment_periods.map(period => ({
id: `${period.started_at}`,
startedAt: new Date(period.started_at),
endedAt: new Date(period.ended_at),
booked: period.booked,
available: !!period.available,
isBookedReachLimit: appointmentPlan.capacity !== -1 && period.booked >= appointmentPlan.capacity,
currentMemberBooked: appointmentPlan.appointment_enrollments.some(
enrollment =>
enrollment.member_id === currentMemberId &&
enrollment.appointment_plan_id === appointmentPlan.id &&
enrollment.started_at === period.started_at &&
!enrollment.canceled_at,
),
})),
isPrivate: appointmentPlan.is_private,
reservationAmount: appointmentPlan.reservation_amount,
reservationType: (appointmentPlan.reservation_type as ReservationType) || 'hour',
}))
})[] = data?.appointment_plan.map(appointmentPlan => ({
id: appointmentPlan.id,
title: appointmentPlan.title,
description: appointmentPlan.description || '',
duration: appointmentPlan.duration,
price: appointmentPlan.price,
phone: null,
supportLocales: appointmentPlan.support_locales,
capacity: appointmentPlan.capacity,
defaultMeetGateway: appointmentPlan.default_meet_gateway,
meetGenerationMethod: appointmentPlan.meet_generation_method,
currency: {
id: appointmentPlan.currency.id,
label: appointmentPlan.currency.label,
unit: appointmentPlan.currency.unit,
name: appointmentPlan.currency.name,
},
rescheduleAmount: appointmentPlan.reschedule_amount,
rescheduleType: appointmentPlan.reschedule_type as ReservationType,
periods: appointmentPlan.appointment_periods.map(period => ({
id: `${period.started_at}`,
startedAt: new Date(period.started_at),
endedAt: new Date(period.ended_at),
booked: period.booked,
available: !!period.available,
isBookedReachLimit: appointmentPlan.capacity !== -1 && period.booked >= appointmentPlan.capacity,
currentMemberBooked: appointmentPlan.appointment_enrollments.some(
enrollment =>
enrollment.member_id === currentMemberId &&
enrollment.appointment_plan_id === appointmentPlan.id &&
enrollment.started_at === period.started_at &&
!enrollment.canceled_at,
),
})),
isPrivate: appointmentPlan.is_private,
reservationAmount: appointmentPlan.reservation_amount,
reservationType: (appointmentPlan.reservation_type as ReservationType) || 'hour',
})) || []

return {
loadingAppointmentPlans: loading,
Expand Down Expand Up @@ -162,16 +159,16 @@ export const useAppointmentPlan = (appointmentPlanId: string, currentMemberId?:

const appointmentPlan:
| (AppointmentPlan & {
periods: AppointmentPeriod[]
creator: {
id: string
avatarUrl: string | null
name: string
abstract: string | null
}
})
periods: AppointmentPeriod[]
creator: {
id: string
avatarUrl: string | null
name: string
abstract: string | null
}
})
| null = data?.appointment_plan_by_pk
? {
? {
id: data.appointment_plan_by_pk.id,
title: data.appointment_plan_by_pk.title,
description: data.appointment_plan_by_pk.description || '',
Expand Down Expand Up @@ -216,8 +213,12 @@ export const useAppointmentPlan = (appointmentPlanId: string, currentMemberId?:
abstract: data.appointment_plan_by_pk.creator?.abstract || null,
},
}
: null
: null
if (appointmentPlan) {
console.log(appointmentPlan.id)
console.log(appointmentPlan?.rescheduleAmount)

}
return {
loadingAppointmentPlan: loading,
errorAppointmentPlan: error,
Expand Down Expand Up @@ -347,13 +348,13 @@ export const useMeetByAppointmentPlanIdAndPeriod = (appointmentPlanId: string, s
)
const meet = data?.meet?.[0]
? {
id: data.meet[0].id,
hostMemberId: data.meet[0].host_member_id,
meetMembers: data.meet[0].meet_members.map(v => ({
id: v.id,
memberId: v.member_id,
})),
}
id: data.meet[0].id,
hostMemberId: data.meet[0].host_member_id,
meetMembers: data.meet[0].meet_members.map(v => ({
id: v.id,
memberId: v.member_id,
})),
}
: null

return {
Expand Down
14 changes: 3 additions & 11 deletions src/pages/MeetingPage/MeetingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import axios from 'axios'
import gql from 'graphql-tag'
import Cookies from 'js-cookie'
import { useApp } from 'lodestar-app-element/src/contexts/AppContext'
import queryString from 'query-string'
import { useState } from 'react'
import { useParams } from 'react-router-dom'
import styled from 'styled-components'
Expand All @@ -29,14 +28,6 @@ const MeetingPage = () => {
const { id: appId, settings } = useApp()
const { username: managerUsername } = useParams<{ username: string }>()
const [isSubmitting, setIsSubmitting] = useState(false)
const queryUrl = window.location.search
const { query } = queryString.parseUrl(queryUrl)

const meetsQueryArray = JSON.parse(settings['custom'])?.['meets'] || []
const meetQueryObject = meetsQueryArray.map((meet: { key: string; name: string }) => ({
name: meet.name,
value: query[meet.key] || '',
}))

const customAdProperty = (propertyName: string) => {
return JSON.parse(settings['custom.ad_property.list'] || '{}')?.['meeting']?.[propertyName] || ''
Expand Down Expand Up @@ -72,6 +63,7 @@ const MeetingPage = () => {
const referal = formEntries.find(entry => entry[0] === 'referal')?.[1]
const fields = formEntries.filter(entry => entry[0] === 'field').flatMap(entry => entry[1].toString().split('/'))
const timeslots = formEntries.filter(entry => entry[0] === 'timeslot').map(entry => entry[1])
const landingPage = Cookies.get('landing') // setting from backend

let utm
try {
Expand Down Expand Up @@ -102,7 +94,7 @@ const MeetingPage = () => {
name: '行銷活動',
value: customMeetingMarketingActivitiesProperty,
},
...meetQueryObject,
{ name: '來源網址', value: landingPage || '' },
],
},
{
Expand All @@ -121,7 +113,7 @@ const MeetingPage = () => {
alert(`發生錯誤,請聯繫網站管理員。錯誤訊息:${message}`)
}
} catch (error) {
console.log(error)
alert(`發生錯誤,請聯繫網站管理員。錯誤訊息:${error}`)
} finally {
setIsSubmitting(false)
window.location.reload()
Expand Down
2 changes: 1 addition & 1 deletion src/types/appointment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type AppointmentPlan = {
supportLocales: string[] | null
currency: CurrencyProps
isPrivate?: boolean
reservationAmount?: number
reservationAmount: number
reservationType?: ReservationType | null
rescheduleAmount: number
rescheduleType: ReservationType | null
Expand Down

0 comments on commit 9f8b5f0

Please sign in to comment.