-
Notifications
You must be signed in to change notification settings - Fork 11k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Adds callout from cloud for subscription upgrade eligibility (#…
…33549) Co-authored-by: Aleksander Nicacio da Silva <aleksander.silva@rocket.chat> Co-authored-by: Lucas Pelegrino <lucas.pelegrino@rocket.chat> Co-authored-by: Kevin Aleman <kaleman960@gmail.com>
- Loading branch information
1 parent
064f6d3
commit 200db1d
Showing
20 changed files
with
407 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@rocket.chat/meteor": minor | ||
"@rocket.chat/core-typings": minor | ||
"@rocket.chat/rest-typings": minor | ||
--- | ||
|
||
Adds a new callout in the subscription page to inform users of subscription upgrade eligibility when applicable. |
42 changes: 42 additions & 0 deletions
42
apps/meteor/app/cloud/server/functions/syncWorkspace/fetchWorkspaceSyncPayload.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { Cloud, Serialized } from '@rocket.chat/core-typings'; | ||
import { serverFetch as fetch } from '@rocket.chat/server-fetch'; | ||
import { v, compile } from 'suretype'; | ||
|
||
import { CloudWorkspaceConnectionError } from '../../../../../lib/errors/CloudWorkspaceConnectionError'; | ||
import { settings } from '../../../../settings/server'; | ||
|
||
const workspaceSyncPayloadSchema = v.object({ | ||
workspaceId: v.string().required(), | ||
publicKey: v.string(), | ||
license: v.string().required(), | ||
}); | ||
|
||
const assertWorkspaceSyncPayload = compile(workspaceSyncPayloadSchema); | ||
|
||
export async function fetchWorkspaceSyncPayload({ | ||
token, | ||
data, | ||
}: { | ||
token: string; | ||
data: Cloud.WorkspaceSyncRequestPayload; | ||
}): Promise<Serialized<Cloud.WorkspaceSyncResponse>> { | ||
const workspaceRegistrationClientUri = settings.get<string>('Cloud_Workspace_Registration_Client_Uri'); | ||
const response = await fetch(`${workspaceRegistrationClientUri}/sync`, { | ||
method: 'POST', | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
body: data, | ||
}); | ||
|
||
if (!response.ok) { | ||
const { error } = await response.json(); | ||
throw new CloudWorkspaceConnectionError(`Failed to connect to Rocket.Chat Cloud: ${error}`); | ||
} | ||
|
||
const payload = await response.json(); | ||
|
||
assertWorkspaceSyncPayload(payload); | ||
|
||
return payload; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
apps/meteor/client/views/admin/subscription/surface/UiKitSubscriptionLicense.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import { useDebouncedCallback } from '@rocket.chat/fuselage-hooks'; | ||
import { UiKitContext, bannerParser, UiKitComponent } from '@rocket.chat/fuselage-ui-kit'; | ||
import type { View } from '@rocket.chat/ui-kit'; | ||
import type { ContextType, Dispatch, ReactElement } from 'react'; | ||
import React, { useMemo } from 'react'; | ||
|
||
import type { SubscriptionLicenseLayout } from './UiKitSubscriptionLicenseSurface'; | ||
import { UiKitSubscriptionLicenseSurface } from './UiKitSubscriptionLicenseSurface'; | ||
import MarkdownText from '../../../../components/MarkdownText'; | ||
import { useUiKitActionManager } from '../../../../uikit/hooks/useUiKitActionManager'; | ||
import { useUiKitView } from '../../../../uikit/hooks/useUiKitView'; | ||
|
||
// TODO: move this to fuselage-ui-kit itself | ||
bannerParser.mrkdwn = ({ text }): ReactElement => <MarkdownText variant='inline' content={text} />; | ||
|
||
type UiKitSubscriptionLicenseProps = { | ||
key: string; | ||
initialView: { | ||
viewId: string; | ||
appId: string; | ||
blocks: SubscriptionLicenseLayout; | ||
}; | ||
}; | ||
|
||
type UseSubscriptionLicenseContextValueParams = { | ||
view: View & { | ||
viewId: string; | ||
}; | ||
values: { | ||
[actionId: string]: { | ||
value: unknown; | ||
blockId?: string | undefined; | ||
}; | ||
}; | ||
updateValues: Dispatch<{ | ||
actionId: string; | ||
payload: { | ||
value: unknown; | ||
blockId?: string | undefined; | ||
}; | ||
}>; | ||
}; | ||
type UseSubscriptionLicenseContextValueReturn = ContextType<typeof UiKitContext>; | ||
|
||
const useSubscriptionLicenseContextValue = ({ | ||
view, | ||
values, | ||
updateValues, | ||
}: UseSubscriptionLicenseContextValueParams): UseSubscriptionLicenseContextValueReturn => { | ||
const actionManager = useUiKitActionManager(); | ||
|
||
const emitInteraction = useMemo(() => actionManager.emitInteraction.bind(actionManager), [actionManager]); | ||
const debouncedEmitInteraction = useDebouncedCallback(emitInteraction, 700); | ||
|
||
return { | ||
action: async ({ appId, viewId, actionId, dispatchActionConfig, blockId, value }): Promise<void> => { | ||
if (!appId || !viewId) { | ||
return; | ||
} | ||
|
||
const emit = dispatchActionConfig?.includes('on_character_entered') ? debouncedEmitInteraction : emitInteraction; | ||
|
||
await emit(appId, { | ||
type: 'blockAction', | ||
actionId, | ||
container: { | ||
type: 'view', | ||
id: viewId, | ||
}, | ||
payload: { | ||
blockId, | ||
value, | ||
}, | ||
}); | ||
}, | ||
updateState: ({ actionId, value, blockId = 'default' }) => { | ||
updateValues({ | ||
actionId, | ||
payload: { | ||
blockId, | ||
value, | ||
}, | ||
}); | ||
}, | ||
...view, | ||
values, | ||
viewId: view.viewId, | ||
}; | ||
}; | ||
|
||
const UiKitSubscriptionLicense = ({ initialView }: UiKitSubscriptionLicenseProps) => { | ||
const { view, values, updateValues } = useUiKitView(initialView); | ||
const contextValue = useSubscriptionLicenseContextValue({ view, values, updateValues }); | ||
|
||
return ( | ||
<UiKitContext.Provider value={contextValue}> | ||
<UiKitComponent render={UiKitSubscriptionLicenseSurface} blocks={view.blocks} /> | ||
</UiKitContext.Provider> | ||
); | ||
}; | ||
|
||
export default UiKitSubscriptionLicense; |
33 changes: 33 additions & 0 deletions
33
apps/meteor/client/views/admin/subscription/surface/UiKitSubscriptionLicenseSurface.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Margins } from '@rocket.chat/fuselage'; | ||
import { createSurfaceRenderer, Surface, FuselageSurfaceRenderer, renderTextObject } from '@rocket.chat/fuselage-ui-kit'; | ||
import type { CalloutBlock, ContextBlock, DividerBlock, ImageBlock, SectionBlock } from '@rocket.chat/ui-kit'; | ||
import type { ReactElement, ReactNode } from 'react'; | ||
import React from 'react'; | ||
|
||
type SubscriptionLicenseSurfaceProps = { | ||
children?: ReactNode; | ||
}; | ||
|
||
type SubscriptionLicenseLayoutBlock = ContextBlock | DividerBlock | ImageBlock | SectionBlock | CalloutBlock; | ||
|
||
export type SubscriptionLicenseLayout = SubscriptionLicenseLayoutBlock[]; | ||
|
||
const SubscriptionLicenseSurface = ({ children }: SubscriptionLicenseSurfaceProps): ReactElement => ( | ||
<Surface type='custom'> | ||
<Margins blockEnd={16}>{children}</Margins> | ||
</Surface> | ||
); | ||
|
||
export class SubscriptionLicenseSurfaceRenderer extends FuselageSurfaceRenderer { | ||
public constructor() { | ||
super(['context', 'divider', 'image', 'section', 'callout']); | ||
} | ||
|
||
plain_text = renderTextObject; | ||
|
||
mrkdwn = renderTextObject; | ||
} | ||
|
||
export default SubscriptionLicenseSurface; | ||
|
||
export const UiKitSubscriptionLicenseSurface = createSurfaceRenderer(SubscriptionLicenseSurface, new SubscriptionLicenseSurfaceRenderer()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.