-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd-attraction.vue
209 lines (196 loc) · 5.09 KB
/
add-attraction.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<template>
<div>
<p class="font-bold text-xl">Add Attraction</p>
<form @submit.prevent="addAttraction">
<div class="flex flex-col gap-y-2 mb-2">
<div>
<p>Is it in Berlin?</p>
<UToggle v-model="isBerlin" />
</div>
<div>
<p>Is it regionally?</p>
<UToggle v-model="isRegional" />
</div>
<div>
<p>Name</p>
<UInput
size="sm"
v-model="name"
placeholder="Enter attraction name" />
</div>
<div>
<p>Opening Hours</p>
<UInput
size="sm"
v-model="openingHoursOnWebsite"
placeholder="Enter opening hours text" />
</div>
<div>
<p>Address</p>
<UInput
size="sm"
v-model="address"
placeholder="Enter attraction address" />
</div>
<div>
<p>Social Media Link</p>
<UInput
size="sm"
v-model="socialMediaLink"
placeholder="Enter attraction address" />
</div>
<div>
<p>Website URL</p>
<UInput
size="sm"
v-model="websiteUrl"
placeholder="Enter attraction address" />
</div>
<div>
<p>Google Maps Link</p>
<UInput
size="sm"
v-model="googleMapsLink"
placeholder="Enter attraction address" />
</div>
<div>
<p>Price per person</p>
<UInput
size="sm"
v-model="price"
placeholder="Enter attraction address" />
</div>
</div>
<div class="flex flex-col">
<p class="font-bold text-xl">Opening Hours</p>
<div class="flex flex-col gap-y-2 overflow-hidden">
<div class="flex flex-row gap-x-2">
<TimeInput
day="Monday"
:opening-hours="openingHours.monday" />
<UButton @click="fillOpeningHours">
Copy opening hours for all days</UButton
>
</div>
<TimeInput
day="Tuesday"
:opening-hours="openingHours.tuesday" />
<TimeInput
day="Wednesday"
:opening-hours="openingHours.wednesday" />
<TimeInput
day="Thursday"
:opening-hours="openingHours.thursday" />
<TimeInput
day="Friday"
:opening-hours="openingHours.friday" />
<TimeInput
day="Saturday"
:opening-hours="openingHours.saturday" />
<TimeInput
day="Sunday"
:opening-hours="openingHours.sunday" />
</div>
</div>
<UButton type="submit">Save</UButton>
</form>
</div>
</template>
<script setup>
import { collection, addDoc } from "firebase/firestore";
import { getFirestore } from "@firebase/firestore";
definePageMeta({
middleware: ["auth"],
});
const isBerlin = ref(false);
const isRegional = ref(true);
const name = ref("");
const socialMediaLink = ref("");
const websiteUrl = ref("");
const googleMapsLink = ref("");
const price = ref(0);
const openingHours = ref({
monday: {
openAt: "",
closeAt: "",
open: true,
},
tuesday: {
openAt: "",
closeAt: "",
open: true,
},
wednesday: {
openAt: "",
closeAt: "",
open: true,
},
thursday: {
openAt: "",
closeAt: "",
open: true,
},
friday: {
openAt: "",
closeAt: "",
open: true,
},
saturday: {
openAt: "",
closeAt: "",
open: true,
},
sunday: {
openAt: "",
closeAt: "",
open: true,
},
});
const openingHoursOnWebsite = ref("");
const address = ref("");
function fillOpeningHours() {
console.log("Filling opening hours");
// maybe need later: const defaultHours = { openAt: "", closeAt: "", open: true };
const days = [
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
"sunday",
];
days.forEach((day) => {
console.log(openingHours.value[day]);
openingHours.value[day] = JSON.parse(
JSON.stringify(openingHours.value["monday"])
);
});
}
async function addAttraction() {
console.log("Saving");
const activity = {
isBerlin: isBerlin.value,
isRegional: isRegional.value,
name: name.value,
socialMediaLink: socialMediaLink.value,
websiteUrl: websiteUrl.value,
googleMapsLink: googleMapsLink.value,
price: price.value,
openingHours: openingHours.value,
openingHoursOnWebsite: openingHoursOnWebsite.value,
address: address.value,
};
try {
console.log("Adding attraction");
const { result } = await $fetch(`/api/firestore/add/activities`, {
method: "POST",
body: activity,
});
console.log("Result", result);
console.log("Attraction added with ID:", result);
} catch (error) {
console.error("Error adding attraction:", error);
}
}
</script>
<style></style>