Skip to content

Commit

Permalink
feat: implement quick appointment booking from the landing page
Browse files Browse the repository at this point in the history
  • Loading branch information
Me-Phew committed Mar 23, 2024
1 parent 0b4016c commit d0ccb32
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
31 changes: 21 additions & 10 deletions src/components/Home/AvailableSlotTile.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@
<div class="buttons">
<div
class="button make-appointment"
@click="bookAppointment"
@keyup.enter="bookAppointment"
@click="makeAppointment"
>
<i class="ph-calendar-plus-light"></i>
{{ t("home.availableSlotTile.book") }}
</div>

<div class="button more-info">
<!-- TODO: Add appointment summary in a modal -->
<!-- <div class="button more-info">
<i class="ph-info-light"></i>
{{ t("home.availableSlotTile.info") }}
</div>
</div> -->
</div>
</div>
</template>

<script>
import { useRouter } from "vue-router";
import { useStore } from "vuex";
import axios from "axios";
import { useI18n } from "vue-i18n";
import { useMessage } from "naive-ui";
Expand All @@ -43,7 +45,7 @@ export default {
type: String,
required: true,
},
firstSlotId: {
id: {
type: String,
required: true,
},
Expand All @@ -53,25 +55,34 @@ export default {
},
},
setup() {
setup(props) {
const { t } = useI18n({ useScope: "global" });
const message = useMessage();
const router = useRouter();
const store = useStore();
const makeAppointment = async () => {
if (!store.getters.isLoggedIn) {
router.push({ name: "login" });
return;
}
const bookAppointment = async () => {
try {
await axios.post(`appointments`, {
// first_slot_id: selectedSlotId.value,
// service_id: selectedService.value.id,
first_slot_id: props.id,
service_id: props.serviceId,
});
message.success(t("snackBars.appointmentMade"));
router.push({ name: "appointmentsList" });
} catch (error) {
message.error(
`${t("snackBars.appointmentsMadeError")} - ${createRequestErrorMessage(error)}`,
);
}
};
return { t, bookAppointment };
return { t, makeAppointment };
},
};
</script>
Expand Down
24 changes: 22 additions & 2 deletions src/components/Home/AvailableSlotsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,25 @@
class="available-dates"
v-if="!loading"
>
<MessageBox
type="info"
class="appointment-cancellation-info"
>
<template #title> Uwaga! </template>
<template #subtitle>
{{ $t("userAppointmentsView.makeAnAppointment.adminCancel") }}
</template>
</MessageBox>

<template
v-for="slot in availableSlots"
:key="slot.id"
>
<AvailableSlotTile
:id="slot.id"
:day="slot.day"
:time="slot.time"
:serviceId="selectedServiceId"
/>
</template>
</div>
Expand All @@ -28,6 +40,7 @@
<script>
import AvailableSlotTile from "@/components/Home/AvailableSlotTile.vue";
import CustomLoader from "@/components/CustomLoader.vue";
import MessageBox from "@/components/MessageBox.vue";
import { computed, ref, watch } from "vue";
import { useStore } from "vuex";
import axios from "axios";
Expand All @@ -39,6 +52,7 @@ export default {
components: {
AvailableSlotTile,
CustomLoader,
MessageBox,
},
props: {
selectedServiceId: {
Expand All @@ -62,8 +76,8 @@ export default {
const now = new Date();
availableSlotsData.value.forEach((service) => {
const date = new Date(`${service.start_time}`);
availableSlotsData.value.forEach((slot) => {
const date = new Date(`${slot.start_time}`);
const day =
date === now
Expand All @@ -73,6 +87,7 @@ export default {
});
slots.push({
id: slot.id,
day: `${day[0].toUpperCase()}${day.slice(1)}`,
time: date.toLocaleTimeString(locale, {
hour: "2-digit",
Expand Down Expand Up @@ -127,6 +142,7 @@ export default {
color: black;
display: grid;
row-gap: 2rem;
grid-template-rows: 1fr auto;
grid-template-columns: repeat(3, 1fr);
justify-items: center;
padding: 3.5rem 10% 3.5rem 10%;
Expand All @@ -135,6 +151,10 @@ export default {
display: flex;
flex-direction: column;
}
.appointment-cancellation-info {
grid-column: 1 / span 3;
}
}
}
</style>
Expand Down
2 changes: 1 addition & 1 deletion src/locales/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@
"noAppointments": "Wygląda na to że nie masz żadnych umówionych wizyt, kliknij przycisk powyżej aby to zrobić"
},
"makeAnAppointment": {
"monthForward": "Maksymalnie miesiąc do przodu",
"monthForward": "Maksymalnie z miesięcznym wyprzedzeniem",
"adminCancel": "Umówioną wizytę może anulować tylko administrator",
"noSlots": "Brak wolnych miejsc",
"makeAnAppointment": "Umów wizytę",
Expand Down
4 changes: 2 additions & 2 deletions src/views/UserAppointments/MakeAnAppointment.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
<CustomModal v-model:open="openMakeAnAppointmentModal">
<template #title>{{ selectedService.name }}</template>
<div class="make-appointment-modal-wrapper">
<MessageBox type="warning">
<MessageBox type="info">
<template #title>
{{ t("userAppointmentsView.makeAnAppointment.monthForward") }}!
{{ t("userAppointmentsView.makeAnAppointment.monthForward") }}
</template>
<template #subtitle>
{{ t("userAppointmentsView.makeAnAppointment.adminCancel") }}!
Expand Down

0 comments on commit d0ccb32

Please sign in to comment.