This repository has been archived by the owner on Jan 2, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 574
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade popup, rework restoring snapshot
- Loading branch information
1 parent
f1b841d
commit 6539ecf
Showing
21 changed files
with
1,954 additions
and
184 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
1,579 changes: 1,579 additions & 0 deletions
1,579
client/src/components/UpgradePopup/ConversationSvg.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
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,43 @@ | ||
import { memo, useContext, useEffect, useState } from 'react'; | ||
import { intervalToDuration } from 'date-fns'; | ||
import { PersonalQuotaContext } from '../../context/personalQuotaContext'; | ||
|
||
type Props = {}; | ||
|
||
const Countdown = ({}: Props) => { | ||
const { resetAt } = useContext(PersonalQuotaContext.Values); | ||
const [timer, setTimer] = useState( | ||
intervalToDuration({ | ||
end: new Date('2023-09-12T14:58:28.035Z'), | ||
start: new Date(), | ||
}), | ||
); | ||
console.log('timer', timer); | ||
|
||
useEffect(() => { | ||
const intervalId = setInterval( | ||
() => | ||
setTimer( | ||
intervalToDuration({ | ||
end: new Date('2023-09-12T14:58:28.035Z'), | ||
start: new Date(), | ||
}), | ||
), | ||
1000, | ||
); | ||
return () => { | ||
clearInterval(intervalId); | ||
}; | ||
}, [resetAt]); | ||
return ( | ||
<span className="w-24 inline-block text-left"> | ||
{timer.days !== undefined | ||
? (timer.days * 24 + timer.hours!).toString().padStart(2, '0') | ||
: '-'} | ||
:{timer.minutes?.toString().padStart(2, '0') || '-'}: | ||
{timer.seconds?.toString().padStart(2, '0') || '-'} | ||
</span> | ||
); | ||
}; | ||
|
||
export default memo(Countdown); |
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,82 @@ | ||
import React, { useCallback, useContext, useEffect, useState } from 'react'; | ||
import { Trans, useTranslation } from 'react-i18next'; | ||
import ModalOrSidebar from '../ModalOrSidebar'; | ||
import Button from '../Button'; | ||
import { CloseSign } from '../../icons'; | ||
import { DeviceContext } from '../../context/deviceContext'; | ||
import { UIContext } from '../../context/uiContext'; | ||
import { getSubscriptionLink } from '../../services/api'; | ||
import { PersonalQuotaContext } from '../../context/personalQuotaContext'; | ||
import Countdown from './Countdown'; | ||
import ConversationSvg from './ConversationSvg'; | ||
|
||
const UpgradePopup = () => { | ||
const { t } = useTranslation(); | ||
const { openLink } = useContext(DeviceContext); | ||
const { refetchQuota } = useContext(PersonalQuotaContext.Handlers); | ||
const { isUpgradePopupOpen, setUpgradePopupOpen } = useContext( | ||
UIContext.UpgradePopup, | ||
); | ||
const [link, setLink] = useState(''); | ||
|
||
useEffect(() => { | ||
getSubscriptionLink().then((resp) => { | ||
setLink(resp.url); | ||
}); | ||
}, []); | ||
|
||
const onClick = useCallback(() => { | ||
openLink(link); | ||
let intervalId = window.setInterval(() => refetchQuota(), 2000); | ||
setTimeout(() => clearInterval(intervalId), 10 * 60 * 1000); | ||
setUpgradePopupOpen(false); | ||
}, [openLink]); | ||
|
||
return ( | ||
<ModalOrSidebar | ||
isSidebar={false} | ||
shouldShow={isUpgradePopupOpen} | ||
onClose={() => setUpgradePopupOpen(false)} | ||
isModalSidebarTransition={false} | ||
setIsModalSidebarTransition={() => {}} | ||
shouldStretch={false} | ||
fullOverlay | ||
containerClassName="max-w-[34rem] max-h-[80vh]" | ||
> | ||
<div className="relative bg-bg-shade overflow-auto"> | ||
<div> | ||
<ConversationSvg /> | ||
</div> | ||
<div className="py-8 px-6 flex flex-col gap-8 items-center"> | ||
<div className="flex flex-col gap-3 text-center"> | ||
<h4 className="h4 text-label-title"> | ||
<Trans>Usage resets in</Trans> <Countdown /> | ||
</h4> | ||
<p className="body-s text-label-base"> | ||
<Trans> | ||
You've run out of free usage for today, please wait for | ||
your quota to reset or upgrade for unlimited usage | ||
</Trans> | ||
</p> | ||
</div> | ||
<Button onClick={onClick}> | ||
<Trans>Upgrade</Trans> | ||
</Button> | ||
</div> | ||
<div className="absolute top-2 right-2"> | ||
<Button | ||
onlyIcon | ||
title={t('Close')} | ||
variant="tertiary" | ||
size="small" | ||
onClick={() => setUpgradePopupOpen(false)} | ||
> | ||
<CloseSign /> | ||
</Button> | ||
</div> | ||
</div> | ||
</ModalOrSidebar> | ||
); | ||
}; | ||
|
||
export default UpgradePopup; |
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
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
Oops, something went wrong.