Skip to content

Commit

Permalink
feat(ui): added update event
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan-Chew authored and qin-guan committed Oct 1, 2023
1 parent a5ba9e1 commit 289d725
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
4 changes: 2 additions & 2 deletions components/admin/home/create-event-popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const mutation = useMutation({
const newEventId = ref('')
async function createEvent() {
event.startDateTime = new Date(event.startDateTime).getTime().toString()
event.endDateTime = new Date(event.endDateTime).getTime().toString()
event.startDateTime = (new Date(event.startDateTime).getTime()/1000).toString()
event.endDateTime = (new Date(event.endDateTime).getTime()/1000).toString()
const res = await mutation.mutateAsync(event)
newEventId.value = res.id
Expand Down
19 changes: 16 additions & 3 deletions components/admin/home/update-event-popup.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script setup lang="ts">
import { useMutation } from '@tanstack/vue-query'
import { watch } from 'vue'
import dayjs from 'dayjs'
import { f7Block, f7BlockTitle, f7Button, f7Link, f7List, f7ListInput, f7NavRight, f7Navbar, f7Page, f7Popup } from 'framework7-vue'
import type { EventWithAttendees } from '~/shared/types'
Expand All @@ -17,8 +18,13 @@ const updatedValues = reactive({
endDateTime: dayjs(Number.parseInt(props.event.endDateTime) * 1000).format('YYYY-MM-DDTHH:mm'),
})
async function updateEvent() {
watch(props, () => {
updatedValues.startDateTime = dayjs(Number.parseInt(props.event.startDateTime) * 1000).format('YYYY-MM-DDTHH:mm')
updatedValues.endDateTime = dayjs(Number.parseInt(props.event.endDateTime) * 1000).format('YYYY-MM-DDTHH:mm')
})
async function updateEvent() {
mutation.mutate(props.event.id)
}
const mutation = useMutation({
Expand Down Expand Up @@ -46,14 +52,21 @@ const mutation = useMutation({
Some content goes here
</f7Block>
<f7List form @submit.prevent="updateEvent">
<f7ListInput :placeholer="props.event.id" label="Event ID" disabled />
<f7ListInput :placeholder="props.event.id" label="Event ID" disabled />
<f7ListInput v-model:value="updatedValues.name" label="Event Name" :placeholder="props.event.name" />
<f7ListInput v-model:value="updatedValues.description" label="Event Description" :placeholder="props.event.description" />
<f7ListInput v-model:value="updatedValues.location" label="Event Location" :placeholder="props.event.location" />
<f7ListInput v-model:value="updatedValues.badgeImage" label="Image URL" :placeholder="props.event.badgeImage" type="url" />
<f7ListInput v-model:value="updatedValues.startDateTime" label="Start Date and Time" :placeholder="props.event.startDateTime" type="datetime-local" />
<f7ListInput v-model:value="updatedValues.endDateTime" label="End Date and Time" :placeholder="props.event.endDateTime" type="datetime-local" />

<f7List inset>
<f7Button v-if="!mutation.isSuccess.value" />
<f7Button v-if="!mutation.isSuccess.value" fill type="submit" preloader :loading="mutation.isLoading.value" :disabled="mutation.isLoading.value">
Update Event
</f7Button>
<f7Button v-if="mutation.isSuccess.value" fill popup-close>
Close
</f7Button>
</f7List>
</f7List>
</f7Page>
Expand Down
4 changes: 2 additions & 2 deletions server/api/event/[id].post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const updateEventRequestBody = z.object({
description: z.string(),
location: z.string(),
badgeImage: z.string().url(),
startDateTime: z.string().datetime(),
endDateTime: z.string().datetime(),
startDateTime: z.string(),
endDateTime: z.string(),
})

export default defineProtectedEventHandler(async (event) => {
Expand Down
4 changes: 2 additions & 2 deletions server/api/event/index.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ const createEventRequestBody = z.object({
description: z.string(),
location: z.string(),
badgeImage: z.string().url(),
startDateTime: z.string().datetime(),
endDateTime: z.string().datetime(),
startDateTime: z.string(),
endDateTime: z.string(),
})

export default defineProtectedEventHandler(async (event) => {
Expand Down
1 change: 1 addition & 0 deletions server/utils/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export function defineProtectedEventHandler<T extends EventHandlerRequest, D>(
})
}


if (options.restrictTo) {
if (!user?.memberType || !options.restrictTo.includes(user.memberType)) {
throw createError({
Expand Down

0 comments on commit 289d725

Please sign in to comment.