|
| 1 | +<script setup lang="ts"> |
| 2 | +import * as api from "@/scripts/api"; |
| 3 | +import { useRouter } from 'vue-router'; |
| 4 | +import { useAccountStore } from '@/scripts/store'; |
| 5 | +import { ref } from 'vue'; |
| 6 | +import { reactive } from 'vue'; |
| 7 | +import { useToast } from 'primevue/usetoast'; |
| 8 | +
|
| 9 | +
|
| 10 | +const path = [{ label: 'New Organization' }]; |
| 11 | +
|
| 12 | +const router = useRouter(); |
| 13 | +const toast = useToast(); |
| 14 | +
|
| 15 | +const accountStore = useAccountStore(); |
| 16 | +if (!accountStore.isLoggedIn) { |
| 17 | + toast.add({ severity: 'error', summary: 'Error', detail: 'Please login first', life: 3000 }); |
| 18 | + router.push('/login'); |
| 19 | +} |
| 20 | +
|
| 21 | +
|
| 22 | +const initialValues = reactive({ |
| 23 | + org_name: "", |
| 24 | + contact_email: "", |
| 25 | + terms: false, |
| 26 | +}); |
| 27 | +
|
| 28 | +interface OrgCreateForm<T> { |
| 29 | + org_name?: T; |
| 30 | + contact_email?: T; |
| 31 | + terms?: T; |
| 32 | +} |
| 33 | +
|
| 34 | +const resolver = ({ values }: { values: OrgCreateForm<string> }) => { |
| 35 | + const errors: OrgCreateForm<{ message: string }[]> = {}; |
| 36 | +
|
| 37 | + if (!values.org_name) { |
| 38 | + errors.org_name = [{ message: 'Organization Name is required.' }]; |
| 39 | + } |
| 40 | +
|
| 41 | + if (!values.contact_email) { |
| 42 | + errors.contact_email = [{ message: 'Your Contact Email is required.' }]; |
| 43 | + } |
| 44 | +
|
| 45 | + if (!values.terms) { |
| 46 | + errors.terms = [{ message: "You must agree to the terms and conditions." }] |
| 47 | + } |
| 48 | +
|
| 49 | + return { |
| 50 | + errors |
| 51 | + }; |
| 52 | +}; |
| 53 | +
|
| 54 | +const name = ref(''); |
| 55 | +const email = ref(''); |
| 56 | +const description = ref(''); |
| 57 | +const display_name = ref(''); |
| 58 | +
|
| 59 | +const inProgress = ref(false); |
| 60 | +const onCreateOrg = async () => { |
| 61 | + inProgress.value = true; |
| 62 | + const res = await api.createOrganization( |
| 63 | + accountStore.auth!, |
| 64 | + { |
| 65 | + name: name.value, |
| 66 | + description: description.value, |
| 67 | + display_name: display_name.value, |
| 68 | + }) |
| 69 | + if (!res.success) { |
| 70 | + toast.add({ severity: 'error', summary: 'Error', detail: res.message, life: 3000 }); |
| 71 | + }; |
| 72 | + inProgress.value = false; |
| 73 | +// router.push("/org/create" + res.data!.id); |
| 74 | +// TODO: redirect to organization home page |
| 75 | +} |
| 76 | +</script> |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +<template> |
| 81 | + <div class="flex-1 flex flex-col"> |
| 82 | + <UniversalToolBar :path></UniversalToolBar> |
| 83 | + <div class="max-w-full w-[768px] md:max-w-[768px] mx-auto"> |
| 84 | + <Panel class="mt-10 w-full h-full"> |
| 85 | + <div class="flex flex-col gap-8 w-full"> |
| 86 | + <div class="mt-10 text-center"> |
| 87 | + <span class="text-gray-500 mb-4">Tell us about your organization</span> |
| 88 | + <h1 class="text-3xl font-bold">Set up your organization</h1> |
| 89 | + </div> |
| 90 | + <div class="flex flex-col"> |
| 91 | + <Form v-slot="$form" :initialValues :resolver class="flex flex-col gap-4 w-full "> |
| 92 | + <div class="card flex flex-col justify-center"> |
| 93 | + <div class="flex flex-col"> |
| 94 | + <label for="name" style="font-size: 20px;">Organization Name *</label> |
| 95 | + <InputText v-model="name" name="name"></InputText> |
| 96 | + </div> |
| 97 | + <Message v-if="$form.org_name?.invalid" severity="error" size="small" variant="simple"> |
| 98 | + {{ |
| 99 | + $form.org_name.error.message }}</Message> |
| 100 | + <div> |
| 101 | + <span class="text-gray-500 mb-4" style="font-size:13px">This will be the name of |
| 102 | + your |
| 103 | + organization on AlgoHub.</span> |
| 104 | + </div> |
| 105 | + <div class="mt-6 flex flex-col"> |
| 106 | + <label for="email" style="font-size: 20px;">Contact Email *</label> |
| 107 | + <InputText v-model="email" email="email"></InputText> |
| 108 | + </div> |
| 109 | + <Message v-if="$form.contact_email?.invalid" severity="error" size="small" |
| 110 | + variant="simple"> |
| 111 | + {{ |
| 112 | + $form.contact_email.error.message }}</Message> |
| 113 | + </div> |
| 114 | + <div class="flex flex-col gap-1 w-full"> |
| 115 | + <div class="flex items-center gap-2"> |
| 116 | + <Checkbox inputId="terms" name="terms" binary /> |
| 117 | + <label for="terms" class="text-sm">I have read and agree to the <a href="#" |
| 118 | + class="underline">Affero |
| 119 | + General Public License v3</a>.</label> |
| 120 | + </div> |
| 121 | + <Message v-if="$form.terms?.invalid" severity="error" size="small" variant="simple">{{ |
| 122 | + $form.terms.error.message }}</Message> |
| 123 | + </div> |
| 124 | + <Button @click="onCreateOrg" :loading="inProgress" label="Next"></Button> |
| 125 | + </Form> |
| 126 | + </div> |
| 127 | + </div> |
| 128 | + </Panel> |
| 129 | + </div> |
| 130 | + <UniversalFooter></UniversalFooter> |
| 131 | + </div> |
| 132 | +</template> |
0 commit comments