@userfrosting/sprinkle-admin
Version:
Admin Sprinkle for UserFrosting 6
42 lines (36 loc) • 1.32 kB
text/typescript
import { ref } from 'vue'
import axios from 'axios'
import { Severity, type AlertInterface } from '@userfrosting/sprinkle-core/interfaces'
import type { GroupCreateRequest, GroupCreateResponse } from '../interfaces'
import { useAlertsStore } from '@userfrosting/sprinkle-core/stores'
// TODO : Add validation
// 'schema://requests/group/create.yaml'
/**
* API Composable
*/
export function useGroupCreateApi() {
const apiLoading = ref<Boolean>(false)
const apiError = ref<AlertInterface | null>(null)
async function submitGroupCreate(data: GroupCreateRequest) {
apiLoading.value = true
apiError.value = null
return axios
.post<GroupCreateResponse>('/api/groups', data)
.then((response) => {
// Add the message to the alert stream
useAlertsStore().push({
title: response.data.title,
description: response.data.description,
style: Severity.Success
})
})
.catch((err) => {
apiError.value = err.response.data
throw apiError.value
})
.finally(() => {
apiLoading.value = false
})
}
return { submitGroupCreate, apiLoading, apiError }
}