-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
160 additions
and
239 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { ref } from 'vue' | ||
import axios from 'axios' | ||
import { Severity, type AlertInterface } from '@userfrosting/sprinkle-core/types' | ||
|
||
/** | ||
* Interfaces - What the API expects and what it returns | ||
*/ | ||
interface GroupEditForm { | ||
slug: string | ||
name: string | ||
description: string | ||
icon: string | ||
} | ||
|
||
interface GroupEditResponse { | ||
success: boolean | ||
message: string | ||
group: GroupEditForm | ||
} | ||
|
||
// TODO : Add validation | ||
// 'schema://requests/group/edit-info.yaml' | ||
|
||
/** | ||
* API Composable | ||
*/ | ||
export function useGroupEditApi() { | ||
const loadingState = ref<Boolean>(false) | ||
const apiError = ref<AlertInterface | null>(null) | ||
|
||
async function submitGroupEdit(slug: string, data: GroupEditForm) { | ||
loadingState.value = true | ||
apiError.value = null | ||
return axios | ||
.put<GroupEditResponse>('/api/groups/g/' + slug, data) | ||
.then((response) => { | ||
return { | ||
success: response.data.success, | ||
message: response.data.message, | ||
group: response.data.group | ||
} | ||
}) | ||
.catch((err) => { | ||
apiError.value = { | ||
...{ | ||
description: 'An error as occurred', | ||
style: Severity.Danger, | ||
closeBtn: true | ||
}, | ||
...err.response.data | ||
} | ||
|
||
throw apiError.value | ||
}) | ||
.finally(() => { | ||
loadingState.value = false | ||
}) | ||
} | ||
|
||
return { submitGroupEdit, loadingState, apiError } | ||
} | ||
|
||
export type { GroupEditForm, GroupEditResponse } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.