-
-
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
214 additions
and
84 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
49 changes: 49 additions & 0 deletions
49
packages/sprinkle-admin/app/assets/composables/useUserUpdateApi.ts
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,49 @@ | ||
import { ref } from 'vue' | ||
import axios from 'axios' | ||
import { Severity, type AlertInterface } from '@userfrosting/sprinkle-core/interfaces' | ||
import type { ApiResponse } from '../interfaces' | ||
|
||
// TODO : Add validation | ||
// 'schema://requests/user/edit-field.yaml' | ||
|
||
/** | ||
* API Composable | ||
*/ | ||
export function useUserUpdateApi() { | ||
const apiLoading = ref<Boolean>(false) | ||
const apiError = ref<AlertInterface | null>(null) | ||
|
||
async function submitUserUpdate(user_name: string, fieldName: string, fieldValue: any) { | ||
apiLoading.value = true | ||
apiError.value = null | ||
|
||
// Assign the field name and value to the payload | ||
const payload: Record<string, any> = {} | ||
payload[fieldName] = fieldValue | ||
|
||
return axios | ||
.put<ApiResponse>('/api/users/u/' + user_name + '/' + fieldName, payload) | ||
.then((response) => { | ||
return { | ||
message: response.data.message | ||
} | ||
}) | ||
.catch((err) => { | ||
apiError.value = { | ||
...{ | ||
description: 'An error as occurred', | ||
style: Severity.Danger, | ||
closeBtn: true | ||
}, | ||
...err.response.data | ||
} | ||
|
||
throw apiError.value | ||
}) | ||
.finally(() => { | ||
apiLoading.value = false | ||
}) | ||
} | ||
|
||
return { submitUserUpdate, apiLoading, apiError } | ||
} |
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,6 @@ | ||
/** | ||
* Interfaces - What the API expects and what it returns | ||
*/ | ||
export interface ApiResponse { | ||
message: string | ||
} |
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 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 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
Oops, something went wrong.