-
-
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.
Add User Create, Edit & Delete Action
- Loading branch information
Showing
24 changed files
with
711 additions
and
110 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 |
---|---|---|
@@ -1,8 +1,20 @@ | ||
// Dashboard | ||
export { useDashboardApi } from './useDashboardApi' | ||
|
||
// Group | ||
export { useGroupApi } from './useGroupApi' | ||
export { useGroupCreateApi } from './useGroupCreateApi' | ||
export { useGroupDeleteApi } from './useGroupDeleteApi' | ||
export { useGroupEditApi } from './useGroupEditApi' | ||
|
||
// Permission | ||
export { usePermissionApi } from './usePermissionApi' | ||
|
||
// Role | ||
export { useRoleApi } from './useRoleApi' | ||
|
||
// User | ||
export { useUserApi } from './useUserApi' | ||
export { useUserCreateApi } from './useUserCreateApi' | ||
export { useUserDeleteApi } from './useUserDeleteApi' | ||
export { useUserEditApi } from './useUserEditApi' |
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
46 changes: 46 additions & 0 deletions
46
packages/sprinkle-admin/app/assets/composables/useUserCreateApi.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,46 @@ | ||
import { ref } from 'vue' | ||
import axios from 'axios' | ||
import { Severity, type AlertInterface } from '@userfrosting/sprinkle-core/interfaces' | ||
import type { UserCreateForm, UserCreateResponse } from '../interfaces' | ||
|
||
// TODO : Add validation | ||
// 'schema://requests/user/create.yaml' | ||
|
||
/** | ||
* API Composable | ||
*/ | ||
export function useUserCreateApi() { | ||
const apiLoading = ref<Boolean>(false) | ||
const apiError = ref<AlertInterface | null>(null) | ||
|
||
async function submitUserCreate(data: UserCreateForm) { | ||
apiLoading.value = true | ||
apiError.value = null | ||
return axios | ||
.post<UserCreateResponse>('/api/users', data) | ||
.then((response) => { | ||
return { | ||
success: response.data.success, | ||
message: response.data.message, | ||
user: response.data.user | ||
} | ||
}) | ||
.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 { submitUserCreate, apiLoading, apiError } | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/sprinkle-admin/app/assets/composables/useUserDeleteApi.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,43 @@ | ||
import { ref } from 'vue' | ||
import axios from 'axios' | ||
import { Severity, type AlertInterface } from '@userfrosting/sprinkle-core/interfaces' | ||
import type { UserDeleteResponse } from '../interfaces' | ||
|
||
/** | ||
* API Composable | ||
*/ | ||
export function useUserDeleteApi() { | ||
// Form data | ||
const loadingState = ref<Boolean>(false) | ||
const apiError = ref<AlertInterface | null>(null) | ||
|
||
async function deleteUser(user_name: string) { | ||
loadingState.value = true | ||
apiError.value = null | ||
return axios | ||
.delete<UserDeleteResponse>('/api/users/u/' + user_name) | ||
.then((response) => { | ||
return { | ||
success: response.data.success, | ||
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(() => { | ||
loadingState.value = false | ||
}) | ||
} | ||
|
||
return { loadingState, apiError, deleteUser } | ||
} |
46 changes: 46 additions & 0 deletions
46
packages/sprinkle-admin/app/assets/composables/useUserEditApi.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,46 @@ | ||
import { ref } from 'vue' | ||
import axios from 'axios' | ||
import { Severity, type AlertInterface } from '@userfrosting/sprinkle-core/interfaces' | ||
import type { UserEditForm, UserEditResponse } from '../interfaces' | ||
|
||
// TODO : Add validation | ||
// 'schema://requests/user/edit-info.yaml' | ||
|
||
/** | ||
* API Composable | ||
*/ | ||
export function useUserEditApi() { | ||
const apiLoading = ref<Boolean>(false) | ||
const apiError = ref<AlertInterface | null>(null) | ||
|
||
async function submitUserEdit(user_name: string, data: UserEditForm) { | ||
apiLoading.value = true | ||
apiError.value = null | ||
return axios | ||
.put<UserEditResponse>('/api/users/u/' + user_name, data) | ||
.then((response) => { | ||
return { | ||
success: response.data.success, | ||
message: response.data.message, | ||
user: response.data.user | ||
} | ||
}) | ||
.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 { submitUserEdit, 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
19 changes: 19 additions & 0 deletions
19
packages/sprinkle-admin/app/assets/interfaces/UserCreateApi.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,19 @@ | ||
import type { UserInterface } from '@userfrosting/sprinkle-account/interfaces' | ||
|
||
/** | ||
* Interfaces - What the API expects and what it returns | ||
*/ | ||
export interface UserCreateForm { | ||
user_name: string | ||
group_id: number | ||
first_name: string | ||
last_name: string | ||
email: string | ||
locale: string | ||
} | ||
|
||
export interface UserCreateResponse { | ||
success: boolean | ||
message: string | ||
user: UserInterface | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/sprinkle-admin/app/assets/interfaces/UserDeleteApi.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,4 @@ | ||
export interface UserDeleteResponse { | ||
success: boolean | ||
message: string | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/sprinkle-admin/app/assets/interfaces/UserEditApi.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,19 @@ | ||
import type { UserInterface } from '@userfrosting/sprinkle-account/interfaces' | ||
|
||
/** | ||
* Interfaces - What the API expects and what it returns | ||
*/ | ||
export interface UserEditForm { | ||
user_name: string | ||
group_id: number | null | ||
first_name: string | ||
last_name: string | ||
email: string | ||
locale: string | ||
} | ||
|
||
export interface UserEditResponse { | ||
success: boolean | ||
message: string | ||
user: UserInterface | ||
} |
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.