-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
328 additions
and
6 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
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
137 changes: 137 additions & 0 deletions
137
packages/frontend/core/src/desktop/pages/upgrade-success/self-host-team/index.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,137 @@ | ||
import { Button, IconButton, notify } from '@affine/component'; | ||
import { AuthPageContainer } from '@affine/component/auth-components'; | ||
import { useMutation } from '@affine/core/components/hooks/use-mutation'; | ||
import { OpenInAppService } from '@affine/core/modules/open-in-app'; | ||
import { copyTextToClipboard } from '@affine/core/utils/clipboard'; | ||
import { generateLicenseKeyMutation, UserFriendlyError } from '@affine/graphql'; | ||
import { Trans, useI18n } from '@affine/i18n'; | ||
import { CopyIcon } from '@blocksuite/icons/rc'; | ||
import { useService } from '@toeverything/infra'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { useSearchParams } from 'react-router-dom'; | ||
|
||
import { PageNotFound } from '../../404'; | ||
import * as styles from './styles.css'; | ||
|
||
/** | ||
* /upgrade-success/self-hosted-team page | ||
* | ||
* only on web | ||
*/ | ||
export const Component = () => { | ||
const [params] = useSearchParams(); | ||
const [key, setKey] = useState<string | null>(null); | ||
const sessionId = params.get('session_id'); | ||
const { trigger: generateLicenseKey } = useMutation({ | ||
mutation: generateLicenseKeyMutation, | ||
}); | ||
|
||
useEffect(() => { | ||
if (sessionId && !key) { | ||
generateLicenseKey({ sessionId }) | ||
.then(({ generateLicenseKey }) => { | ||
setKey(generateLicenseKey); | ||
}) | ||
.catch(e => { | ||
const error = UserFriendlyError.fromAnyError(e); | ||
console.error(error); | ||
|
||
notify.error({ | ||
title: error.name, | ||
message: error.message, | ||
}); | ||
}); | ||
} | ||
}, [generateLicenseKey, key, sessionId]); | ||
|
||
if (!sessionId) { | ||
return <PageNotFound noPermission />; | ||
} | ||
|
||
if (key) { | ||
return <Success licenseKey={key} />; | ||
} else { | ||
return ( | ||
<AuthPageContainer | ||
title={'Failed to generate the license key'} | ||
subtitle={ | ||
<span> | ||
Failed to generate the license key, please contact our {''} | ||
<a href="mailto:[email protected]" className={styles.mail}> | ||
customer support | ||
</a> | ||
. | ||
</span> | ||
} | ||
></AuthPageContainer> | ||
); | ||
} | ||
}; | ||
|
||
const Success = ({ licenseKey }: { licenseKey: string }) => { | ||
const t = useI18n(); | ||
const openInAppService = useService(OpenInAppService); | ||
|
||
const openAFFiNE = useCallback(() => { | ||
openInAppService.showOpenInAppPage(); | ||
}, [openInAppService]); | ||
|
||
const onCopy = useCallback(() => { | ||
copyTextToClipboard(licenseKey) | ||
.then(success => { | ||
if (success) { | ||
notify.success({ | ||
title: t['com.affine.payment.license-success.copy'](), | ||
}); | ||
} | ||
}) | ||
.catch(err => { | ||
console.error(err); | ||
notify.error({ title: 'Copy failed, please try again later' }); | ||
}); | ||
}, [licenseKey, t]); | ||
|
||
const subtitle = ( | ||
<span className={styles.leftContentText}> | ||
<span>{t['com.affine.payment.license-success.text-1']()}</span> | ||
<span> | ||
<Trans | ||
i18nKey={'com.affine.payment.license-success.text-2'} | ||
components={{ | ||
1: ( | ||
<a | ||
href="mailto:[email protected]" | ||
className={styles.mail} | ||
/> | ||
), | ||
}} | ||
/> | ||
</span> | ||
</span> | ||
); | ||
return ( | ||
<AuthPageContainer | ||
title={t['com.affine.payment.license-success.title']()} | ||
subtitle={subtitle} | ||
> | ||
<div className={styles.content}> | ||
<div className={styles.licenseKeyContainer}> | ||
{licenseKey} | ||
<IconButton | ||
icon={<CopyIcon />} | ||
className={styles.icon} | ||
size="20" | ||
tooltip={t['Copy']()} | ||
onClick={onCopy} | ||
/> | ||
</div> | ||
<div>{t['com.affine.payment.license-success.hint']()}</div> | ||
<div> | ||
<Button variant="primary" size="extraLarge" onClick={openAFFiNE}> | ||
{t['com.affine.payment.license-success.open-affine']()} | ||
</Button> | ||
</div> | ||
</div> | ||
</AuthPageContainer> | ||
); | ||
}; |
37 changes: 37 additions & 0 deletions
37
packages/frontend/core/src/desktop/pages/upgrade-success/self-host-team/styles.css.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,37 @@ | ||
import { cssVar } from '@toeverything/theme'; | ||
import { cssVarV2 } from '@toeverything/theme/v2'; | ||
import { style } from '@vanilla-extract/css'; | ||
export const leftContentText = style({ | ||
fontSize: cssVar('fontBase'), | ||
fontWeight: 400, | ||
lineHeight: '1.6', | ||
maxWidth: '548px', | ||
}); | ||
export const mail = style({ | ||
color: cssVar('linkColor'), | ||
textDecoration: 'none', | ||
':visited': { | ||
color: cssVar('linkColor'), | ||
}, | ||
}); | ||
export const content = style({ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: '28px', | ||
}); | ||
|
||
export const licenseKeyContainer = style({ | ||
width: '100%', | ||
display: 'flex', | ||
justifyContent: 'space-between', | ||
alignItems: 'center', | ||
backgroundColor: cssVarV2('layer/background/secondary'), | ||
borderRadius: '4px', | ||
border: `1px solid ${cssVarV2('layer/insideBorder/blackBorder')}`, | ||
padding: '8px 10px', | ||
gap: '8px', | ||
}); | ||
|
||
export const icon = style({ | ||
color: cssVarV2('icon/primary'), | ||
}); |
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
3 changes: 3 additions & 0 deletions
3
packages/frontend/graphql/src/graphql/generate-license-key.gql
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,3 @@ | ||
mutation generateLicenseKey($sessionId: String!) { | ||
generateLicenseKey(sessionId: $sessionId) | ||
} |
Oops, something went wrong.