|
6 | 6 | CardBody, |
7 | 7 | Col, |
8 | 8 | Dropdown, |
9 | | - DropdownItem, |
10 | | - DropdownMenu, |
11 | 9 | DropdownToggle, |
12 | 10 | Input, |
13 | 11 | Row, |
|
19 | 17 | import Breadcrumb from '$lib/common/Breadcrumb.svelte'; |
20 | 18 | import TablePagination from '$lib/common/TablePagination.svelte'; |
21 | 19 | import LoadingToComplete from '$lib/common/LoadingToComplete.svelte'; |
22 | | - import { getUsers } from '$lib/services/user-service'; |
| 20 | + import { getUsers, updateUser } from '$lib/services/user-service'; |
23 | 21 | import UserItem from './user-item.svelte'; |
24 | 22 | import { getAgents } from '$lib/services/agent-service'; |
25 | 23 | |
26 | 24 | const duration = 3000; |
27 | 25 | const firstPage = 1; |
28 | | - const pageSize = 5; |
| 26 | + const pageSize = 15; |
29 | 27 |
|
30 | 28 | const initPager = { page: firstPage, size: pageSize }; |
31 | 29 |
|
32 | 30 | let isLoading = false; |
33 | 31 | let isComplete = false; |
34 | 32 | let isError = false; |
35 | | - let successText = ''; |
36 | | - let errorText = ''; |
| 33 | + let successText = 'User has been updated!'; |
| 34 | + let errorText = 'Failed to update user!'; |
37 | 35 |
|
38 | 36 | /** @type {import('$commonTypes').Pagination} */ |
39 | 37 | let pager = { ...initPager, count: 0 }; |
|
60 | 58 | }); |
61 | 59 |
|
62 | 60 | async function getPagedUsers() { |
63 | | - users = await getUsers(filter); |
64 | | - refresh(); |
| 61 | + isLoading = true; |
| 62 | + return new Promise((resolve, reject) => { |
| 63 | + getUsers(filter).then(res => { |
| 64 | + users = res; |
| 65 | + refresh(); |
| 66 | + resolve(res); |
| 67 | + }).finally(() => { |
| 68 | + setTimeout(() => { |
| 69 | + isLoading = false; |
| 70 | + }, 200); |
| 71 | + }); |
| 72 | + }); |
65 | 73 | } |
66 | 74 |
|
67 | 75 | async function getPagedAgents() { |
|
123 | 131 | page: pageNum, |
124 | 132 | size: pageSize |
125 | 133 | }; |
126 | | -
|
127 | 134 | getPagedUsers(); |
128 | 135 | } |
| 136 | +
|
| 137 | + /** @param {any} e */ |
| 138 | + function saveUser(e) { |
| 139 | + const data = e.detail.updatedData; |
| 140 | + isLoading = true; |
| 141 | + updateUser(data).then(() => { |
| 142 | + isLoading = false; |
| 143 | + isComplete = true; |
| 144 | + postUpdateUser(data); |
| 145 | + setTimeout(() => { |
| 146 | + isComplete = false; |
| 147 | + }, duration); |
| 148 | + }).catch(() => { |
| 149 | + isLoading = false; |
| 150 | + isComplete = false; |
| 151 | + isError = true; |
| 152 | + setTimeout(() => { |
| 153 | + isError = false; |
| 154 | + }, duration); |
| 155 | + }); |
| 156 | + } |
| 157 | +
|
| 158 | + /** @param {import('$userTypes').UserModel} data */ |
| 159 | + function postUpdateUser(data) { |
| 160 | + const newItems = users?.items?.map(x => { |
| 161 | + if (x.id === data.id) { |
| 162 | + return { ...data }; |
| 163 | + } |
| 164 | + return x; |
| 165 | + }) || []; |
| 166 | + users = { |
| 167 | + ...users, |
| 168 | + items: newItems |
| 169 | + }; |
| 170 | + } |
129 | 171 | </script> |
130 | 172 |
|
131 | 173 |
|
|
183 | 225 | </Row> |
184 | 226 | </CardBody> |
185 | 227 | <CardBody> |
186 | | - <div class="table-responsive"> |
| 228 | + <div class="table-responsive thin-scrollbar"> |
187 | 229 | <Table class="align-middle nowrap users-table" bordered> |
188 | 230 | <thead> |
189 | 231 | <tr> |
190 | 232 | <th scope="col">{$_('User Name')}</th> |
191 | 233 | <th scope="col">{$_('Full Name')}</th> |
192 | 234 | <th scope="col">{$_('External Id')}</th> |
193 | | - <th scope="col">{$_('Role')}</th> |
| 235 | + <th scope="col" class="user-plain-col">{$_('Role')}</th> |
194 | 236 | <th scope="col">{$_('Source')}</th> |
195 | 237 | <th scope="col" class="user-permission-col">{$_('Permissions')}</th> |
196 | | - <th scope="col" class="user-agent-col">{$_('Agents')}</th> |
197 | 238 | <th scope="col">{$_('')}</th> |
198 | 239 | </tr> |
199 | 240 | </thead> |
200 | 241 | <tbody> |
201 | 242 | {#each users.items as item, idx (idx)} |
202 | | - <UserItem item={item} agents={agents} /> |
| 243 | + <UserItem item={item} agents={agents} on:save={e => saveUser(e)} /> |
203 | 244 | {/each} |
204 | 245 | </tbody> |
205 | 246 | </Table> |
|
0 commit comments