diff --git a/net/web/src/context/useAppContext.hook.js b/net/web/src/context/useAppContext.hook.js index fa2ced89..17991f25 100644 --- a/net/web/src/context/useAppContext.hook.js +++ b/net/web/src/context/useAppContext.hook.js @@ -79,9 +79,7 @@ export function useAppContext(websocket) { await appCreate(username, password, token) }, setAdmin: (token) => { -console.log("TOKEN SET!", token); updateState({ adminToken: token }); -console.log("TOKEN SET: done"); }, clearAdmin: () => { updateState({ adminToken: null }); diff --git a/net/web/src/dashboard/Dashboard.jsx b/net/web/src/dashboard/Dashboard.jsx index 3db75f43..bf69f76b 100644 --- a/net/web/src/dashboard/Dashboard.jsx +++ b/net/web/src/dashboard/Dashboard.jsx @@ -6,10 +6,7 @@ import { AccountItem } from './accountItem/AccountItem'; export function Dashboard() { -console.log("IN DASHBOARD"); - const { state, actions } = useDashboard(); -console.log("IN DASHBOARD here"); const onClipboard = (value) => { navigator.clipboard.writeText(value); diff --git a/net/web/src/dashboard/accountItem/AccountItem.jsx b/net/web/src/dashboard/accountItem/AccountItem.jsx index 497d5da0..11bc2d15 100644 --- a/net/web/src/dashboard/accountItem/AccountItem.jsx +++ b/net/web/src/dashboard/accountItem/AccountItem.jsx @@ -13,12 +13,48 @@ export function AccountItem({ item, remove }) { title: 'Are you sure you want to delete the account?', icon: , onOk() { - actions.remove(); + applyRemoveAccount(); }, onCancel() {}, }); } + const applyRemoveAccount = async () => { + try { + await actions.remove(); + } + catch(err) { + Modal.error({ + title: 'Failed to Remove Account', + content: 'Please try again.', + }); + } + } + + const applyAccountStatus = async (status) => { + try { + await actions.setStatus(status); + } + catch(err) { + Modal.error({ + title: 'Failed to Set Account Status', + content: 'Please try again.', + }); + } + } + + const setAccountAccess = async () => { + try { + await actions.setAccessLink(); + } + catch(err) { + Modal.error({ + title: 'Failed to Set Account Access', + content: 'Please try again.', + }); + } + } + const onClipboard = (value) => { navigator.clipboard.writeText(value); }; @@ -29,25 +65,25 @@ export function AccountItem({ item, remove }) { return ( -
+
-
-
{ state.handle }
-
{ state.guid }
+
+
{ state.handle }
+
{ state.guid }
-
+
{ state.display === 'small' && ( <> } - loading={state.accessBusy} onClick={() => actions.setAccessLink()}> + loading={state.accessBusy} onClick={setAccountAccess}> { state.disabled && ( } - loading={state.statusBusy} onClick={() => actions.setStatus(false)}> + loading={state.statusBusy} onClick={() => applyAccountStatus(false)}> )} { !state.disabled && ( } - loading={state.statusBusy} onClick={() => actions.setStatus(true)}> + loading={state.statusBusy} onClick={() => applyAccountStatus(true)}> )} } loading={state.removeBusy} onClick={removeAccount}> @@ -57,18 +93,18 @@ export function AccountItem({ item, remove }) { <> } - loading={state.accessBusy} onClick={() => actions.setAccessLink()}> + loading={state.accessBusy} onClick={setAccountAccess}> { state.disabled && ( } - loading={state.statusBusy} onClick={() => actions.setStatus(false)}> + loading={state.statusBusy} onClick={() => applyAccountStatus(false)}> )} { !state.disabled && ( } - loading={state.statusBusy} onClick={() => actions.setStatus(true)}> + loading={state.statusBusy} onClick={() => applyAccountStatus(true)}> )} @@ -82,15 +118,15 @@ export function AccountItem({ item, remove }) { footer={[ ]} onCancel={() => actions.setShowAccess(false)}> -
-
Browser Link:
- +
+
Browser Link:
+
{accessLink()}
-
-
App Token:
-
{state.accessToken}
+
+
App Token:
+
{state.accessToken}
diff --git a/net/web/src/dashboard/accountItem/useAccountItem.hook.js b/net/web/src/dashboard/accountItem/useAccountItem.hook.js index 42e5b0b3..5bc93327 100644 --- a/net/web/src/dashboard/accountItem/useAccountItem.hook.js +++ b/net/web/src/dashboard/accountItem/useAccountItem.hook.js @@ -42,13 +42,14 @@ export function useAccountItem(item, remove) { if (!state.accessBusy) { updateState({ accessBusy: true }); try { - let access = await addAccountAccess(app.state.adminToken, item.accountId); - updateState({ accessToken: access, showAccess: true }); + const access = await addAccountAccess(app.state.adminToken, item.accountId); + updateState({ accessToken: access, showAccess: true, accessBusy: false }); } catch (err) { - window.alert(err); + console.log(err); + updateState({ accessBusy: false }); + throw new Error('failed to generate token'); } - updateState({ accessBusy: false }); } }, setShowAccess: (showAccess) => { @@ -59,12 +60,13 @@ export function useAccountItem(item, remove) { updateState({ removeBusy: true }); try { await remove(state.accountId); + updateState({ removeBusy: false }); } catch(err) { console.log(err); - window.alert(err); + updateState({ removeBusy: false }); + throw new Error('failed to remove account'); } - updateState({ removeBusy: false }); } }, setStatus: async (disabled) => { @@ -72,13 +74,13 @@ export function useAccountItem(item, remove) { updateState({ statusBusy: true }); try { await setAccountStatus(app.state.adminToken, item.accountId, disabled); - updateState({ disabled, activeClass: disabled ? 'inactive' : 'active' }); + updateState({ statusBusy: false, disabled, activeClass: disabled ? 'inactive' : 'active' }); } catch(err) { console.log(err); - window.alert(err); + updateState({ statusBusy: false }); + throw new Error('failed to set account status'); } - updateState({ statusBusy: false }); } }, }; diff --git a/net/web/src/dashboard/useDashboard.hook.js b/net/web/src/dashboard/useDashboard.hook.js index b1038f03..15e054b5 100644 --- a/net/web/src/dashboard/useDashboard.hook.js +++ b/net/web/src/dashboard/useDashboard.hook.js @@ -64,7 +64,7 @@ export function useDashboard() { }, removeAccount: async (accountId) => { await removeAccount(app.state.adminToken, accountId); - actions.getAccounts(); + syncAccounts(); }, setHost: (domain) => { updateState({ domain });