aboutsummaryrefslogtreecommitdiffstats
path: root/web/components/AddConference.vue
blob: 95154d40089b3d496989a5befc955532fbdb17b2 (plain)
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
<script setup lang="ts">
import { format } from 'date-fns';
import { type Event as ScheduledEvent } from '~/stores/schedule';

const errorStore = useErrorStore();
const config = useRuntimeConfig();
const loading = ref(false)

const emit = defineEmits(['update']);

const addConference = async (e: Event) => {
  const target = e.target as HTMLFormElement;
  const formData = new FormData(target);
  loading.value = true

  $api(config.public.baseURL + '/conference', {
    method: 'POST',
    body: JSON.stringify(Object.fromEntries(formData)),
    onResponse: ({ response }) => {
      loading.value = false
      if (!response.ok) {
        errorStore.setError(response._data?.message || 'An unknown error occurred');
        return
      }
      emit('update')
    },
  });
}

</script>

<template>
  <div>
    <form @submit.prevent="(e) => addConference(e)">
      <div class="form-group">
        <label for="url" class="form-label">
          Schedule data URL
        </label>
        <div class="form-input-container">
          <Input id="url" name="url" required />
        </div>
      </div>

      <div class="form-submit">
        <Button type="submit" :loading="loading">
          Add
        </Button>
      </div>
    </form>
  </div>
</template>

<style scoped>
</style>