Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
['name' => 'appointment#show', 'url' => '/appointment/{token}', 'verb' => 'GET'],
['name' => 'booking#getBookableSlots', 'url' => '/appointment/{appointmentConfigToken}/slots', 'verb' => 'GET'],
['name' => 'booking#bookSlot', 'url' => '/appointment/{appointmentConfigToken}/book', 'verb' => 'POST'],
['name' => 'booking#confirmBooking', 'url' => '/appointment/confirm/{token}', 'verb' => 'GET'],
['name' => 'booking#showConfirmBooking', 'url' => '/appointment/confirm/{token}', 'verb' => 'GET'],
['name' => 'booking#confirmBooking', 'url' => '/appointment/confirm/{token}', 'verb' => 'POST'],
// Public views
['name' => 'publicView#public_index_with_branding', 'url' => '/p/{token}', 'verb' => 'GET'],
['name' => 'publicView#public_index_with_branding', 'url' => '/p/{token}/{view}/{timeRange}', 'verb' => 'GET', 'postfix' => 'publicview.timerange'],
Expand Down
64 changes: 46 additions & 18 deletions lib/Controller/BookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,8 @@ public function bookSlot(string $appointmentConfigToken,
*
* @param string $token
* @return TemplateResponse
* @throws Exception
*/
public function confirmBooking(string $token): TemplateResponse {
public function showConfirmBooking(string $token): TemplateResponse {
try {
$booking = $this->bookingService->findByToken($token);
} catch (ClientException $e) {
Expand All @@ -219,7 +218,7 @@ public function confirmBooking(string $token): TemplateResponse {

try {
$config = $this->appointmentConfigService->findById($booking->getApptConfigId());
} catch (ServiceException $e) {
} catch (ClientException $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
return new TemplateResponse(
Application::APP_ID,
Expand All @@ -229,27 +228,56 @@ public function confirmBooking(string $token): TemplateResponse {
);
}

$link = $this->urlGenerator->linkToRouteAbsolute('calendar.appointment.show', [ 'token' => $config->getToken() ]);
try {
$booking = $this->bookingService->confirmBooking($booking, $config);
} catch (ClientException $e) {
$this->logger->warning($e->getMessage(), ['exception' => $e]);
}
$link = $this->urlGenerator->linkToRouteAbsolute('calendar.appointment.show', ['token' => $config->getToken()]);

$this->initialState->provideInitialState(
'appointment-link',
$link
);
$this->initialState->provideInitialState(
'booking',
$booking
);
$this->initialState->provideInitialState('appointment-link', $link);
$this->initialState->provideInitialState('booking', $booking);
$this->initialState->provideInitialState('booking-token', $token);

return new TemplateResponse(
Application::APP_ID,
'appointments/booking-conflict',
'appointments/confirmation',
[],
TemplateResponse::RENDER_AS_GUEST
);
}

/**
* @PublicPage
* @NoCSRFRequired
*
* @param string $token
* @return JsonResponse
*/
public function confirmBooking(string $token): JsonResponse {
try {
$booking = $this->bookingService->findByToken($token);
} catch (ClientException $e) {
$this->logger->warning($e->getMessage(), ['exception' => $e]);
return JsonResponse::fail(null, Http::STATUS_NOT_FOUND);
}

if ($booking->isConfirmed()) {
return JsonResponse::success(['confirmed' => true]);
}

try {
$config = $this->appointmentConfigService->findById($booking->getApptConfigId());
} catch (ClientException $e) {
$this->logger->error($e->getMessage(), ['exception' => $e]);
return JsonResponse::fail(null, Http::STATUS_NOT_FOUND);
}

try {
$booking = $this->bookingService->confirmBooking($booking, $config);
} catch (NoSlotFoundException $e) {
$this->logger->warning($e->getMessage(), ['exception' => $e]);
return JsonResponse::fail('slot_unavailable', Http::STATUS_CONFLICT);
} catch (ClientException $e) {
$this->logger->warning($e->getMessage(), ['exception' => $e]);
return JsonResponse::fail(null, Http::STATUS_UNPROCESSABLE_ENTITY);
}

return JsonResponse::success(['confirmed' => $booking->isConfirmed()]);
}
}
4 changes: 2 additions & 2 deletions lib/Service/Appointments/BookingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public function __construct(AvailabilityGenerator $availabilityGenerator,
}

/**
* @throws ClientException|DbException
* @throws NoSlotFoundException|ClientException|DbException
*/
public function confirmBooking(Booking $booking, AppointmentConfig $config): Booking {
$bookingSlot = current($this->getAvailableSlots($config, $booking->getStart(), $booking->getEnd()));

if (!$bookingSlot) {
throw new ClientException('Slot for booking is not available any more');
throw new NoSlotFoundException('Slot for booking is not available any more');
}

$tz = new DateTimeZone($booking->getTimezone());
Expand Down
5 changes: 4 additions & 1 deletion src/appointments/main-confirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Vue from 'vue'
import Confirmation from '../views/Appointments/Confirmation.vue'

// CSP config for webpack dynamic chunk loading

__webpack_nonce__ = btoa(getRequestToken())

// Correct the root of the app for chunk loading
Expand All @@ -24,13 +23,17 @@ __webpack_public_path__ = linkTo('calendar', 'js/')
Vue.prototype.$t = translate
Vue.prototype.$n = translatePlural

const link = loadState('calendar', 'appointment-link')
const booking = loadState('calendar', 'booking')
const token = loadState('calendar', 'booking-token')

export default new Vue({
el: '#appointment-confirmation',
render: (h) => h(Confirmation, {
props: {
link,
booking,
token,
},
}),
})
40 changes: 0 additions & 40 deletions src/appointments/main-conflict.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import moment from '@nextcloud/moment'
export default {
name: 'Conflict',
name: 'BookingResult',
props: {
link: {
required: true,
Expand Down
149 changes: 133 additions & 16 deletions src/views/Appointments/Confirmation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,157 @@
- SPDX-License-Identifier: AGPL-3.0-or-later
-->
<template>
<div class="update">
{{ $t('calendar', 'The slot for your appointment has been confirmed') }}
<br>
<br>
{{ $t('calendar', 'Appointment Details:') }}
<br>
{{ $t('calendar', 'Time:') }} <b>{{ startDate }}</b> - <b>{{ endDate }}</b>
<br>
{{ $t('calendar', 'Booked for:') }} {{ booking.displayName }} ({{ booking.email }})
<br>
<br>
<div class="guest-box">
<div v-if="status === 'expired'" class="update">
<h2>{{ $t('calendar', 'This booking link is no longer valid') }}</h2>
<p>{{ $t('calendar', 'The confirmation link has expired or has already been used. Please contact the organizer to rebook.') }}</p>
</div>

<BookingResult
v-else-if="status !== 'pending'"
:link="link"
:confirmed="status === 'confirmed'"
:start="booking.start"
:end="booking.end" />

<div v-else class="update">
<h2>{{ $t('calendar', 'Confirm your appointment') }}</h2>
<div class="booking__date">
<IconCalendar :size="16" />
{{ date }}
</div>
<div class="booking__time">
<IconTime :size="16" />
{{ startTime }} – {{ endTime }}
</div>
<div class="booking__time">
<IconTimezone :size="16" />
{{ booking.timezone }}
</div>
<div class="booking__attendee">
<IconAccount :size="16" />
{{ booking.displayName }} ({{ booking.email }})
</div>
<NcNoteCard v-if="error" type="error">
{{ $t('calendar', 'Could not confirm the appointment. Please try again later or contact the organizer.') }}
</NcNoteCard>
<div class="buttons">
<NcButton variant="primary" :disabled="loading" @click="confirm">
<template #icon>
<NcLoadingIcon v-if="loading" :size="16" />
<IconCheck v-else :size="16" />
</template>
{{ $t('calendar', 'Confirm') }}
</NcButton>
</div>
</div>
</div>
</template>

<script>
import moment from '@nextcloud/moment'
import axios from '@nextcloud/axios'
import { generateUrl } from '@nextcloud/router'
import { NcButton, NcLoadingIcon, NcNoteCard } from '@nextcloud/vue'
import IconAccount from 'vue-material-design-icons/AccountOutline.vue'
import IconCalendar from 'vue-material-design-icons/CalendarOutline.vue'
import IconCheck from 'vue-material-design-icons/CheckOutline.vue'
import IconTime from 'vue-material-design-icons/ClockTimeFourOutline.vue'
import IconTimezone from 'vue-material-design-icons/Web.vue'
import BookingResult from './BookingResult.vue'
import { timeStampToLocaleDate, timeStampToLocaleTime } from '../../utils/localeTime.js'

export default {
name: 'Confirmation',

components: {
BookingResult,
NcButton,
NcLoadingIcon,
NcNoteCard,
IconAccount,
IconCheck,
IconCalendar,
IconTime,
IconTimezone,
},

props: {
booking: {
required: true,
type: Object,
},

link: {
required: true,
type: String,
},

token: {
required: true,
type: String,
},
},

data() {
return {
status: this.booking.confirmed ? 'confirmed' : 'pending',
loading: false,
error: false,
}
},

computed: {
startDate() {
return moment(this.booking.start * 1000).format('LLL')
date() {
return timeStampToLocaleDate(this.booking.start, this.booking.timezone)
},

startTime() {
return timeStampToLocaleTime(this.booking.start, this.booking.timezone)
},

endDate() {
return moment(this.booking.end * 1000).format('LLL')
endTime() {
return timeStampToLocaleTime(this.booking.end, this.booking.timezone)
},
},

methods: {
async confirm() {
this.loading = true
this.error = false
try {
const url = generateUrl('/apps/calendar/appointment/confirm/{token}', { token: this.token })
await axios.post(url)
this.status = 'confirmed'
} catch (e) {
if (e.response?.status === 409) {
this.status = 'conflict'
} else if (e.response?.status === 404) {
this.status = 'expired'
} else {
this.error = true
}
} finally {
this.loading = false
}
},
},
}
</script>

<style lang="scss" scoped>
.booking__date,
.booking__time,
.booking__attendee {
display: flex;
align-items: center;
gap: 4px;
padding-top: 10px;
}

.buttons {
display: flex;
align-items: center;
gap: 8px;
margin-top: 20px;
}
</style>
12 changes: 0 additions & 12 deletions templates/appointments/booking-conflict.php

This file was deleted.

Loading
Loading