Files
archie/ui/src/accounts/CreateAccount.vue
T

27 lines
2.2 KiB
Vue

<script setup lang="ts">
import { ref } from "vue";
import { Input } from "@/components/ui/input";
import { Section } from "@/components/ui/section";
import { Button } from "@/components/ui/button";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { api } from "@/lib/api";
import { ROLE_LABELS, ROLES } from "@/org/org";
const emit=defineEmits<{created:[]}>();
// Owner is granted from the member table, not when creating an account.
const assignable = ROLES.filter((role) => role !== "owner");
const name=ref("");const email=ref("");const password=ref("");const role=ref("viewer");const busy=ref(false);const error=ref("");
async function create(){busy.value=true;error.value="";try{await api.createAccount({display_name:name.value,email:email.value,password:password.value,role:role.value});name.value=email.value=password.value="";emit("created")}catch(cause){error.value=String((cause as Error).message||cause)}finally{busy.value=false}}
</script>
<template>
<Section title="Create a local account" class="max-w-md">
<form class="space-y-3" @submit.prevent="create">
<label for="new-account-name" class="block space-y-1 text-sm">Name<Input id="new-account-name" v-model="name" required maxlength="200" autocomplete="off" /></label>
<label for="new-account-email" class="block space-y-1 text-sm">Email<Input id="new-account-email" v-model="email" type="email" required autocomplete="off" :spellcheck="false" /></label>
<label for="new-account-password" class="block space-y-1 text-sm">Initial password<Input id="new-account-password" v-model="password" type="password" required minlength="15" maxlength="1024" autocomplete="new-password" /></label>
<div class="block space-y-1 text-sm"><label for="new-account-role">Role</label><Select v-model="role"><SelectTrigger id="new-account-role" class="w-full"><SelectValue /></SelectTrigger><SelectContent><SelectItem v-for="choice in assignable" :key="choice" :value="choice">{{ ROLE_LABELS[choice] }}</SelectItem></SelectContent></Select></div>
<p v-if="error" role="alert" class="text-sm text-danger">{{error}} <a class="underline" href="/?reauth=1">Sign in again</a></p>
<Button type="submit" :disabled="busy">Create account</Button>
</form>
</Section>
</template>