Skip to content

Commit

Permalink
Cloud Page
Browse files Browse the repository at this point in the history
  • Loading branch information
ggazzo committed Apr 4, 2022
1 parent 057d4e6 commit 8d64734
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
1 change: 1 addition & 0 deletions client/hooks/useMethodData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const useMethodData = <MethodName extends keyof ServerMethods, Result = A
}, [reset, getData, args, resolve, dispatchToastMessage, reject]);

useEffect(() => {
console.log('as');
fetchData();
}, [fetchData]);

Expand Down
30 changes: 16 additions & 14 deletions client/views/admin/cloud/CloudPage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Box, Button, ButtonGroup, Margins } from '@rocket.chat/fuselage';
import React, { useEffect, ReactNode, useMemo } from 'react';
import React, { useEffect, ReactNode } from 'react';

import Page from '../../../components/Page';
import { useSetModal } from '../../../contexts/ModalContext';
Expand All @@ -16,6 +16,8 @@ import WorkspaceLoginSection from './WorkspaceLoginSection';
import WorkspaceRegistrationSection from './WorkspaceRegistrationSection';
import { cloudConsoleUrl } from './constants';

const args = [] as const;

const CloudPage = function CloudPage(): ReactNode {
const t = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();
Expand All @@ -30,12 +32,12 @@ const CloudPage = function CloudPage(): ReactNode {
const token = useQueryStringParameter('token');

const finishOAuthAuthorization = useMethod('cloud:finishOAuthAuthorization');
// const checkRegisterStatus = useMethod('cloud:checkRegisterStatus');

const checkRegisterStatus = useMethodData(
'cloud:checkRegisterStatus',
useMemo(() => [], []),
);
const { reload, ...checkRegisterStatus } = useMethodData('cloud:checkRegisterStatus', args);

useEffect(() => {
console.log('checkRegisterStatus', checkRegisterStatus);
}, [checkRegisterStatus]);

const connectWorkspace = useMethod('cloud:connectWorkspace');

Expand Down Expand Up @@ -76,25 +78,25 @@ const CloudPage = function CloudPage(): ReactNode {
const isConnected = await connectWorkspace(token);

if (!isConnected) {
throw Error(t('An error occured connecting' as Parameters<typeof t>[0]));
throw Error(t('occurredof t>[0]));
}
dispatchToastMessage({ type: 'success', message: t('Connected') });
}
} catch (error) {
dispatchToastMessage({ type: 'error', message: error });
} finally {
await checkRegisterStatus.reload();
await reload();
}
};
acceptWorkspaceToken();
}, [checkRegisterStatus, connectWorkspace, dispatchToastMessage, t, token]);
}, [reload, connectWorkspace, dispatchToastMessage, t, token]);
const handleManualWorkspaceRegistrationButtonClick = (): void => {
const handleModalClose = (): void => {
setModal(null);
checkRegisterStatus.reload();
reload();
};
setModal(<ManualWorkspaceRegistrationModal onClose={handleModalClose} />);
};
Expand Down Expand Up @@ -129,22 +131,22 @@ const CloudPage = function CloudPage(): ReactNode {
<>
{isWorkspaceRegistered ? (
<>
<WorkspaceLoginSection onRegisterStatusChange={checkRegisterStatus.reload} />
<TroubleshootingSection onRegisterStatusChange={checkRegisterStatus.reload} />
<WorkspaceLoginSection onRegisterStatusChange={reload} />
<TroubleshootingSection onRegisterStatusChange={reload} />
</>
) : (
<WorkspaceRegistrationSection
email={checkRegisterStatus.value.email}
token={checkRegisterStatus.value.token}
workspaceId={checkRegisterStatus.value.workspaceId}
uniqueId={checkRegisterStatus.value.uniqueId}
onRegisterStatusChange={checkRegisterStatus.reload}
onRegisterStatusChange={reload}
/>
)}
</>
)}

{!isConnectToCloudDesired && <ConnectToCloudSection onRegisterStatusChange={checkRegisterStatus.reload} />}
{!isConnectToCloudDesired && <ConnectToCloudSection onRegisterStatusChange={reload} />}
</Margins>
</Box>
</Page.ScrollableContentWithShadow>
Expand Down

0 comments on commit 8d64734

Please sign in to comment.