RoleAndPermissionAPI.jsx
3 months ago
TrashUserRoleModel.jsx
3 months ago
UserDisplayModal.jsx
3 months ago
UserRoleTable.jsx
2 months ago
RoleAndPermissionAPI.jsx
122 lines
| 1 | import apiFetch from '@wordpress/api-fetch'; |
| 2 | |
| 3 | const { restURL, security } = |
| 4 | typeof evf_roles_and_permission !== 'undefined' && evf_roles_and_permission; |
| 5 | const base = restURL + 'everest-forms/v1/roels_and_permission/'; |
| 6 | |
| 7 | const urls = { |
| 8 | bulkAssignPermission: base + 'bulk-assign-permission-based-on-role', |
| 9 | getWPRoles: base + 'get-wp-roles', |
| 10 | addUserManager: base + 'add-user-manager', |
| 11 | getManagers: base + 'get-managers', |
| 12 | removeManager: base + 'remove-manager', |
| 13 | bulkRemoveManager: base + 'bulk-remove-managers', |
| 14 | getWPUsers: base + 'get-wp-users', |
| 15 | }; |
| 16 | |
| 17 | export const bulkAssignPermission = async (checkedItems) => { |
| 18 | return apiFetch({ |
| 19 | path: urls.bulkAssignPermission, |
| 20 | method: 'POST', |
| 21 | headers: { |
| 22 | 'X-WP-Nonce': security, |
| 23 | }, |
| 24 | data: { |
| 25 | request: { |
| 26 | checked_roles: checkedItems, |
| 27 | }, |
| 28 | }, |
| 29 | }).then((res) => res); |
| 30 | }; |
| 31 | |
| 32 | export const getWPRoles = async () => { |
| 33 | return apiFetch({ |
| 34 | path: urls.getWPRoles, |
| 35 | method: 'get', |
| 36 | headers: { |
| 37 | 'X-WP-Nonce': security, |
| 38 | }, |
| 39 | }).then((res) => res); |
| 40 | }; |
| 41 | |
| 42 | export const addManagerRole = async (user_email, assignedPermissions) => { |
| 43 | return apiFetch({ |
| 44 | path: urls.addUserManager, |
| 45 | method: 'POST', |
| 46 | headers: { |
| 47 | 'X-WP-Nonce': security, |
| 48 | }, |
| 49 | data: { |
| 50 | request: { |
| 51 | user_email: user_email, |
| 52 | assigned_permission: assignedPermissions, |
| 53 | }, |
| 54 | }, |
| 55 | }).then((res) => res); |
| 56 | }; |
| 57 | |
| 58 | export const getManagers = async ( |
| 59 | offset = '', |
| 60 | pageSize = '', |
| 61 | searchManager = '', |
| 62 | ) => { |
| 63 | return apiFetch({ |
| 64 | path: urls.getManagers, |
| 65 | method: 'POST', |
| 66 | headers: { |
| 67 | 'X-WP-Nonce': security, |
| 68 | }, |
| 69 | data: { |
| 70 | request: { |
| 71 | offset: offset, |
| 72 | page_size: pageSize, |
| 73 | search_manager: searchManager, |
| 74 | }, |
| 75 | }, |
| 76 | }).then((res) => res); |
| 77 | }; |
| 78 | |
| 79 | export const removeManager = async (userID) => { |
| 80 | return apiFetch({ |
| 81 | path: urls.removeManager, |
| 82 | method: 'POST', |
| 83 | headers: { |
| 84 | 'X-WP-Nonce': security, |
| 85 | }, |
| 86 | data: { |
| 87 | request: { |
| 88 | user_id: userID, |
| 89 | }, |
| 90 | }, |
| 91 | }).then((res) => res); |
| 92 | }; |
| 93 | |
| 94 | export const getWPUsers = async ({ page = 1, search = '' } = {}) => { |
| 95 | const params = new URLSearchParams({ page }); |
| 96 | if (search) { |
| 97 | params.set('search', search); |
| 98 | } |
| 99 | return apiFetch({ |
| 100 | path: `${urls.getWPUsers}?${params.toString()}`, |
| 101 | method: 'GET', |
| 102 | headers: { |
| 103 | 'X-WP-Nonce': security, |
| 104 | }, |
| 105 | }).then((res) => res); |
| 106 | }; |
| 107 | |
| 108 | export const bulkRemoveManager = async (userIDs) => { |
| 109 | return apiFetch({ |
| 110 | path: urls.bulkRemoveManager, |
| 111 | method: 'POST', |
| 112 | headers: { |
| 113 | 'X-WP-Nonce': security, |
| 114 | }, |
| 115 | data: { |
| 116 | request: { |
| 117 | user_ids: userIDs, |
| 118 | }, |
| 119 | }, |
| 120 | }); |
| 121 | }; |
| 122 |