nuxt-users 1.26.0 → 1.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/NUsersList.vue +14 -28
- package/dist/runtime/components/NUsersList.vue.d.ts +0 -68
- package/dist/runtime/components/NUsersLogoutLink.vue.d.ts +2 -2
- package/dist/runtime/components/NUsersUserForm.vue.d.ts +2 -2
- package/dist/runtime/composables/useUsers.d.ts +20 -0
- package/dist/runtime/composables/useUsers.js +55 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
## v1.27.0
|
|
5
|
+
|
|
6
|
+
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.26.0...v1.27.0)
|
|
7
|
+
|
|
8
|
+
### 🚀 Enhancements
|
|
9
|
+
|
|
10
|
+
- Emit error ([0818b80](https://github.com/rrd108/nuxt-users/commit/0818b80))
|
|
11
|
+
- Expose useUsers composable ([485d81c](https://github.com/rrd108/nuxt-users/commit/485d81c))
|
|
12
|
+
|
|
13
|
+
### 🏡 Chore
|
|
14
|
+
|
|
15
|
+
- **release:** V1.26.0 ([3f90a9c](https://github.com/rrd108/nuxt-users/commit/3f90a9c))
|
|
16
|
+
|
|
17
|
+
### ❤️ Contributors
|
|
18
|
+
|
|
19
|
+
- Rrd108 ([@rrd108](https://github.com/rrd108))
|
|
20
|
+
|
|
4
21
|
## v1.26.0
|
|
5
22
|
|
|
6
23
|
[compare changes](https://github.com/rrd108/nuxt-users/compare/v1.25.0...v1.26.0)
|
package/dist/module.json
CHANGED
|
@@ -1,41 +1,27 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { onMounted } from "vue";
|
|
3
|
+
import { useUsers } from "../composables/useUsers";
|
|
4
4
|
import { defaultDisplayFields, defaultFieldLabels } from "nuxt-users/utils";
|
|
5
5
|
defineProps({
|
|
6
6
|
displayFields: { type: Array, required: false, default: () => defaultDisplayFields },
|
|
7
7
|
fieldLabels: { type: Object, required: false, default: () => defaultFieldLabels }
|
|
8
8
|
});
|
|
9
9
|
const emit = defineEmits(["editClick", "delete"]);
|
|
10
|
-
const {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const response = await $fetch(`${nuxtUsers.apiBasePath}?page=${page}&limit=${limit}`);
|
|
20
|
-
users.value = response.users;
|
|
21
|
-
pagination.value = response.pagination;
|
|
22
|
-
} catch (err) {
|
|
23
|
-
error.value = err instanceof Error ? err.message : "Failed to fetch users";
|
|
24
|
-
} finally {
|
|
25
|
-
loading.value = false;
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
const refresh = () => {
|
|
29
|
-
fetchUsers();
|
|
30
|
-
};
|
|
31
|
-
defineExpose({
|
|
32
|
-
refresh
|
|
33
|
-
});
|
|
10
|
+
const {
|
|
11
|
+
users,
|
|
12
|
+
pagination,
|
|
13
|
+
loading,
|
|
14
|
+
error,
|
|
15
|
+
fetchUsers,
|
|
16
|
+
removeUser
|
|
17
|
+
} = useUsers();
|
|
34
18
|
onMounted(() => {
|
|
35
|
-
|
|
19
|
+
if (users.value.length === 0) {
|
|
20
|
+
fetchUsers();
|
|
21
|
+
}
|
|
36
22
|
});
|
|
37
23
|
const handleDelete = (user) => {
|
|
38
|
-
|
|
24
|
+
removeUser(user.id);
|
|
39
25
|
emit("delete", user);
|
|
40
26
|
};
|
|
41
27
|
</script>
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
interface Props {
|
|
2
|
-
displayFields?: string[];
|
|
3
|
-
fieldLabels?: Record<string, string>;
|
|
4
|
-
}
|
|
5
|
-
declare var __VLS_1: {}, __VLS_3: {
|
|
6
|
-
loading: boolean;
|
|
7
|
-
}, __VLS_5: {
|
|
8
|
-
error: string | null;
|
|
9
|
-
}, __VLS_7: {}, __VLS_9: {}, __VLS_16: {
|
|
10
|
-
user: any;
|
|
11
|
-
index: number;
|
|
12
|
-
}, __VLS_27: {
|
|
13
|
-
pagination: {
|
|
14
|
-
page: number;
|
|
15
|
-
limit: number;
|
|
16
|
-
total: number;
|
|
17
|
-
totalPages: number;
|
|
18
|
-
hasNext: boolean;
|
|
19
|
-
hasPrev: boolean;
|
|
20
|
-
} | null;
|
|
21
|
-
}, __VLS_29: {
|
|
22
|
-
pagination: {
|
|
23
|
-
page: number;
|
|
24
|
-
limit: number;
|
|
25
|
-
total: number;
|
|
26
|
-
totalPages: number;
|
|
27
|
-
hasNext: boolean;
|
|
28
|
-
hasPrev: boolean;
|
|
29
|
-
} | null;
|
|
30
|
-
fetchUsers: (page?: number, limit?: number) => Promise<void>;
|
|
31
|
-
loading: boolean;
|
|
32
|
-
};
|
|
33
|
-
type __VLS_Slots = {} & {
|
|
34
|
-
title?: (props: typeof __VLS_1) => any;
|
|
35
|
-
} & {
|
|
36
|
-
loading?: (props: typeof __VLS_3) => any;
|
|
37
|
-
} & {
|
|
38
|
-
error?: (props: typeof __VLS_5) => any;
|
|
39
|
-
} & {
|
|
40
|
-
noUsers?: (props: typeof __VLS_7) => any;
|
|
41
|
-
} & {
|
|
42
|
-
usersList?: (props: typeof __VLS_9) => any;
|
|
43
|
-
} & {
|
|
44
|
-
user?: (props: typeof __VLS_16) => any;
|
|
45
|
-
} & {
|
|
46
|
-
paginationInfo?: (props: typeof __VLS_27) => any;
|
|
47
|
-
} & {
|
|
48
|
-
pagination?: (props: typeof __VLS_29) => any;
|
|
49
|
-
};
|
|
50
|
-
declare const __VLS_component: import("vue").DefineComponent<Props, {
|
|
51
|
-
refresh: () => void;
|
|
52
|
-
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
53
|
-
delete: (user: User) => void;
|
|
54
|
-
editClick: (user: User) => void;
|
|
55
|
-
}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
|
|
56
|
-
onDelete?: ((user: User) => any) | undefined;
|
|
57
|
-
onEditClick?: ((user: User) => any) | undefined;
|
|
58
|
-
}>, {
|
|
59
|
-
displayFields: string[];
|
|
60
|
-
fieldLabels: Record<string, string>;
|
|
61
|
-
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
62
|
-
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
63
|
-
export default _default;
|
|
64
|
-
type __VLS_WithSlots<T, S> = T & {
|
|
65
|
-
new (): {
|
|
66
|
-
$slots: S;
|
|
67
|
-
};
|
|
68
|
-
};
|
|
@@ -16,12 +16,12 @@ type __VLS_Slots = {} & {
|
|
|
16
16
|
default?: (props: typeof __VLS_1) => any;
|
|
17
17
|
};
|
|
18
18
|
declare const __VLS_component: import("vue").DefineComponent<LogoutLinkProps, void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
19
|
-
click: () => any;
|
|
20
19
|
error: (error: string) => any;
|
|
20
|
+
click: () => any;
|
|
21
21
|
success: () => any;
|
|
22
22
|
}, string, import("vue").PublicProps, Readonly<LogoutLinkProps> & Readonly<{
|
|
23
|
-
onClick?: (() => any) | undefined;
|
|
24
23
|
onError?: ((error: string) => any) | undefined;
|
|
24
|
+
onClick?: (() => any) | undefined;
|
|
25
25
|
onSuccess?: (() => any) | undefined;
|
|
26
26
|
}>, {
|
|
27
27
|
redirectTo: string;
|
|
@@ -3,12 +3,12 @@ interface Props {
|
|
|
3
3
|
user?: User | null;
|
|
4
4
|
}
|
|
5
5
|
declare const _default: import("vue").DefineComponent<Props, void, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
6
|
-
cancel: () => any;
|
|
7
6
|
error: (error: unknown) => any;
|
|
7
|
+
cancel: () => any;
|
|
8
8
|
submit: (userData: User) => any;
|
|
9
9
|
}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{
|
|
10
|
-
onCancel?: (() => any) | undefined;
|
|
11
10
|
onError?: ((error: unknown) => any) | undefined;
|
|
11
|
+
onCancel?: (() => any) | undefined;
|
|
12
12
|
onSubmit?: ((userData: User) => any) | undefined;
|
|
13
13
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
14
14
|
export default _default;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { User } from '../../types.js';
|
|
2
|
+
interface Pagination {
|
|
3
|
+
page: number;
|
|
4
|
+
limit: number;
|
|
5
|
+
total: number;
|
|
6
|
+
totalPages: number;
|
|
7
|
+
hasNext: boolean;
|
|
8
|
+
hasPrev: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const useUsers: () => {
|
|
11
|
+
users: import("vue").Ref<User[], User[]>;
|
|
12
|
+
pagination: import("vue").Ref<Pagination | null, Pagination | null>;
|
|
13
|
+
loading: import("vue").Ref<boolean, boolean>;
|
|
14
|
+
error: import("vue").Ref<string | null, string | null>;
|
|
15
|
+
fetchUsers: (page?: number, limit?: number) => Promise<void>;
|
|
16
|
+
updateUser: (updatedUser: User) => void;
|
|
17
|
+
addUser: (newUser: User) => void;
|
|
18
|
+
removeUser: (userId: number) => Promise<void>;
|
|
19
|
+
};
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useState, useRuntimeConfig } from "#imports";
|
|
2
|
+
const usersState = useState("users", () => []);
|
|
3
|
+
const paginationState = useState("users-pagination", () => null);
|
|
4
|
+
export const useUsers = () => {
|
|
5
|
+
const { public: { nuxtUsers } } = useRuntimeConfig();
|
|
6
|
+
const loading = useState("users-loading", () => false);
|
|
7
|
+
const error = useState("users-error", () => null);
|
|
8
|
+
const fetchUsers = async (page = 1, limit = 100) => {
|
|
9
|
+
if (loading.value) return;
|
|
10
|
+
loading.value = true;
|
|
11
|
+
error.value = null;
|
|
12
|
+
try {
|
|
13
|
+
const response = await $fetch(`${nuxtUsers.apiBasePath}?page=${page}&limit=${limit}`);
|
|
14
|
+
usersState.value = response.users;
|
|
15
|
+
paginationState.value = response.pagination;
|
|
16
|
+
} catch (err) {
|
|
17
|
+
error.value = err instanceof Error ? err.message : "Failed to fetch users";
|
|
18
|
+
usersState.value = [];
|
|
19
|
+
paginationState.value = null;
|
|
20
|
+
} finally {
|
|
21
|
+
loading.value = false;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const updateUser = (updatedUser) => {
|
|
25
|
+
const index = usersState.value.findIndex((u) => u.id === updatedUser.id);
|
|
26
|
+
if (index !== -1) {
|
|
27
|
+
usersState.value[index] = updatedUser;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const addUser = (newUser) => {
|
|
31
|
+
usersState.value.unshift(newUser);
|
|
32
|
+
};
|
|
33
|
+
const removeUser = async (userId) => {
|
|
34
|
+
loading.value = true;
|
|
35
|
+
error.value = null;
|
|
36
|
+
try {
|
|
37
|
+
await $fetch(`${nuxtUsers.apiBasePath}/${userId}`, { method: "DELETE" });
|
|
38
|
+
usersState.value = usersState.value.filter((u) => u.id !== userId);
|
|
39
|
+
} catch (err) {
|
|
40
|
+
error.value = err instanceof Error ? err.message : "Failed to delete user";
|
|
41
|
+
} finally {
|
|
42
|
+
loading.value = false;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
users: usersState,
|
|
47
|
+
pagination: paginationState,
|
|
48
|
+
loading,
|
|
49
|
+
error,
|
|
50
|
+
fetchUsers,
|
|
51
|
+
updateUser,
|
|
52
|
+
addUser,
|
|
53
|
+
removeUser
|
|
54
|
+
};
|
|
55
|
+
};
|
package/package.json
CHANGED