11import { isNumber } from 'lodash' ;
2- import { MouseEventHandler , useCallback , useMemo , type ReactNode } from 'react' ;
2+ import { MouseEventHandler , SessionDataTestId , useCallback , useMemo , type ReactNode } from 'react' ;
33import styled from 'styled-components' ;
44import { useDispatch } from 'react-redux' ;
55import { ModalBasicHeader } from '../../../../SessionWrapperModal' ;
@@ -46,6 +46,7 @@ import { proButtonProps } from '../../../SessionProInfoModal';
4646import { useIsProGroupsAvailable } from '../../../../../hooks/useIsProAvailable' ;
4747import { SessionSpinner } from '../../../../loading' ;
4848import { SpacerMD } from '../../../../basic/Text' ;
49+ import { sleepFor } from '../../../../../session/utils/Promise' ;
4950
5051// TODO: There are only 2 props here and both are passed to the nonorigin modal dispatch, can probably be in their own object
5152type SectionProps = {
@@ -201,31 +202,25 @@ function ProNonProContinueButton({ returnToThisModalAction, centerAlign }: Secti
201202 const backendErrorButtons = useBackendErrorDialogButtons ( ) ;
202203
203204 const handleClick = useCallback ( ( ) => {
204- if ( isError ) {
205- dispatch (
206- updateLocalizedPopupDialog ( {
207- title : { token : 'proStatusError' } ,
208- description : { token : 'proStatusNetworkErrorDescription' } ,
209- overrideButtons : backendErrorButtons ,
210- } )
211- ) ;
212- } else if ( isLoading ) {
213- dispatch (
214- updateLocalizedPopupDialog ( {
215- title : { token : 'proStatusLoading' } ,
216- description : { token : 'proStatusLoadingDescription' } ,
217- } )
218- ) ;
219- } else {
220- dispatch (
221- userSettingsModal ( {
222- userSettingsPage : 'proNonOriginating' ,
223- nonOriginatingVariant : 'upgrade' ,
224- overrideBackAction : returnToThisModalAction ,
225- centerAlign,
226- } )
227- ) ;
228- }
205+ dispatch (
206+ isError
207+ ? updateLocalizedPopupDialog ( {
208+ title : { token : 'proStatusError' } ,
209+ description : { token : 'proStatusNetworkErrorDescription' } ,
210+ overrideButtons : backendErrorButtons ,
211+ } )
212+ : isLoading
213+ ? updateLocalizedPopupDialog ( {
214+ title : { token : 'proStatusLoading' } ,
215+ description : { token : 'proStatusLoadingDescription' } ,
216+ } )
217+ : userSettingsModal ( {
218+ userSettingsPage : 'proNonOriginating' ,
219+ nonOriginatingVariant : 'upgrade' ,
220+ overrideBackAction : returnToThisModalAction ,
221+ centerAlign,
222+ } )
223+ ) ;
229224 } , [ dispatch , isLoading , isError , backendErrorButtons , centerAlign , returnToThisModalAction ] ) ;
230225
231226 if ( ! neverHadPro ) {
@@ -273,7 +268,7 @@ const StatsLabel = styled.div<{ disabled?: boolean }>`
273268const proBoxShadow = '0 4px 4px 0 rgba(0, 0, 0, 0.25)' ;
274269
275270function ProStats ( ) {
276- const proLongerMessagesSent = Storage . get ( SettingsKey . proLongerMessagesSent ) || 3000 ;
271+ const proLongerMessagesSent = Storage . get ( SettingsKey . proLongerMessagesSent ) || 0 ;
277272 const proPinnedConversations = Storage . get ( SettingsKey . proPinnedConversations ) || 0 ;
278273 const proBadgesSent = Storage . get ( SettingsKey . proBadgesSent ) || 0 ;
279274 const proGroupsUpgraded = Storage . get ( SettingsKey . proGroupsUpgraded ) || 0 ;
@@ -475,10 +470,12 @@ function ProSettings({ returnToThisModalAction, centerAlign }: SectionProps) {
475470function ProFeatureItem ( {
476471 textElement,
477472 iconElement,
473+ dataTestId,
478474 onClick,
479475} : {
480476 iconElement : ReactNode ;
481477 textElement : ReactNode ;
478+ dataTestId : SessionDataTestId ;
482479 onClick ?: ( ) => Promise < void > ;
483480} ) {
484481 const isDarkTheme = useIsDarkTheme ( ) ;
@@ -488,7 +485,7 @@ function ProFeatureItem({
488485 disabled = { ! onClick }
489486 // eslint-disable-next-line @typescript-eslint/no-misused-promises
490487 onClick = { onClick }
491- data-testid = { 'invalid-data-testid' }
488+ data-testid = { dataTestId }
492489 isDarkTheme = { isDarkTheme }
493490 defaultCursorWhenDisabled
494491 >
@@ -569,6 +566,7 @@ function ProFeatureIconElement({
569566
570567function getProFeatures ( userHasPro : boolean ) : Array <
571568 {
569+ dataTestId : SessionDataTestId ;
572570 id :
573571 | 'proLongerMessages'
574572 | 'proUnlimitedPins'
@@ -581,6 +579,7 @@ function getProFeatures(userHasPro: boolean): Array<
581579> {
582580 return [
583581 {
582+ dataTestId : 'longer-messages-pro-settings-menu-item' ,
584583 id : 'proLongerMessages' ,
585584 title : { token : 'proLongerMessages' as const } ,
586585 description : {
@@ -591,6 +590,7 @@ function getProFeatures(userHasPro: boolean): Array<
591590 unicode : LUCIDE_ICONS_UNICODE . MESSAGE_SQUARE ,
592591 } ,
593592 {
593+ dataTestId : 'more-pins-pro-settings-menu-item' ,
594594 id : 'proUnlimitedPins' ,
595595 title : { token : 'proUnlimitedPins' as const } ,
596596 description : {
@@ -601,18 +601,21 @@ function getProFeatures(userHasPro: boolean): Array<
601601 unicode : LUCIDE_ICONS_UNICODE . PIN ,
602602 } ,
603603 {
604+ dataTestId : 'animated-display-picture-pro-settings-menu-item' ,
604605 id : 'proAnimatedDisplayPictures' ,
605606 title : { token : 'proAnimatedDisplayPictures' as const } ,
606607 description : { token : 'proAnimatedDisplayPicturesDescription' as const } ,
607608 unicode : LUCIDE_ICONS_UNICODE . SQUARE_PLAY ,
608609 } ,
609610 {
611+ dataTestId : 'badges-pro-settings-menu-item' ,
610612 id : 'proBadges' ,
611613 title : { token : 'proBadges' as const } ,
612614 description : { token : 'proBadgesDescription' as const } ,
613615 unicode : LUCIDE_ICONS_UNICODE . RECTANGLE_ELLIPSES ,
614616 } ,
615617 {
618+ dataTestId : 'loads-more-pro-settings-menu-item' ,
616619 id : 'plusLoadsMore' ,
617620 title : { token : 'plusLoadsMore' as const } ,
618621 description : {
@@ -637,6 +640,7 @@ function ProFeatures() {
637640 { proFeatures . map ( ( m , i ) => {
638641 return (
639642 < ProFeatureItem
643+ dataTestId = { m . dataTestId }
640644 onClick = {
641645 m . id === 'plusLoadsMore'
642646 ? async ( ) => {
@@ -729,9 +733,7 @@ function ManageProCurrentAccess({ returnToThisModalAction, centerAlign }: Sectio
729733// TODO: add logic to call libsession state
730734function useRecoverProStatus ( ) {
731735 const fetchAccess = useCallback ( async ( ) => {
732- await new Promise ( resolve => {
733- setTimeout ( resolve , 5000 ) ;
734- } ) ;
736+ await sleepFor ( 5000 ) ;
735737 return { ok : false } ;
736738 } , [ ] ) ;
737739
@@ -749,69 +751,62 @@ function ManageProPreviousAccess({ returnToThisModalAction, centerAlign }: Secti
749751 const backendErrorButtons = useBackendErrorDialogButtons ( ) ;
750752
751753 const handleClickRenew = useCallback ( ( ) => {
752- if ( isError ) {
753- dispatch (
754- updateLocalizedPopupDialog ( {
755- title : { token : 'proStatusError' } ,
756- description : { token : 'proStatusRenewError' } ,
757- overrideButtons : backendErrorButtons ,
758- } )
759- ) ;
760- } else if ( isLoading ) {
761- dispatch (
762- updateLocalizedPopupDialog ( {
763- title : { token : 'proStatusLoading' } ,
764- description : { token : 'checkingProStatusRenew' } ,
765- } )
766- ) ;
767- } else {
768- dispatch (
769- userSettingsModal ( {
770- userSettingsPage : 'proNonOriginating' ,
771- nonOriginatingVariant : 'renew' ,
772- overrideBackAction : returnToThisModalAction ,
773- centerAlign,
774- } )
775- ) ;
776- }
754+ dispatch (
755+ isError
756+ ? updateLocalizedPopupDialog ( {
757+ title : { token : 'proStatusError' } ,
758+ description : { token : 'proStatusRenewError' } ,
759+ overrideButtons : backendErrorButtons ,
760+ } )
761+ : isLoading
762+ ? updateLocalizedPopupDialog ( {
763+ title : { token : 'proStatusLoading' } ,
764+ description : { token : 'checkingProStatusRenew' } ,
765+ } )
766+ : userSettingsModal ( {
767+ userSettingsPage : 'proNonOriginating' ,
768+ nonOriginatingVariant : 'renew' ,
769+ overrideBackAction : returnToThisModalAction ,
770+ centerAlign,
771+ } )
772+ ) ;
777773 } , [ dispatch , isLoading , isError , backendErrorButtons , centerAlign , returnToThisModalAction ] ) ;
778774
779775 const handleClickRecover = useCallback ( async ( ) => {
780776 const result = await fetchRecoverAccess ( ) ;
781777
782778 if ( result . ok ) {
783- dispatch (
779+ return dispatch (
784780 updateLocalizedPopupDialog ( {
785781 title : { token : 'proAccessRestored' } ,
786782 description : { token : 'proAccessRestoredDescription' } ,
787783 } )
788784 ) ;
789- } else {
790- dispatch (
791- updateLocalizedPopupDialog ( {
792- title : { token : 'proAccessNotFound' } ,
793- description : { token : 'proAccessNotFoundDescription' } ,
794- overrideButtons : [
795- {
796- label : { token : 'helpSupport' } ,
797- dataTestId : 'pro-backend-error-support-button' ,
798- onClick : ( ) => {
799- showLinkVisitWarningDialog (
800- 'https://sessionapp.zendesk.com/hc/sections/4416517450649-Support' ,
801- dispatch
802- ) ;
803- } ,
804- closeAfterClick : true ,
805- } ,
806- {
807- label : { token : 'close' } ,
808- dataTestId : 'modal-close-button' ,
809- closeAfterClick : true ,
810- } ,
811- ] ,
812- } )
813- ) ;
814785 }
786+ return dispatch (
787+ updateLocalizedPopupDialog ( {
788+ title : { token : 'proAccessNotFound' } ,
789+ description : { token : 'proAccessNotFoundDescription' } ,
790+ overrideButtons : [
791+ {
792+ label : { token : 'helpSupport' } ,
793+ dataTestId : 'pro-backend-error-support-button' ,
794+ onClick : ( ) => {
795+ showLinkVisitWarningDialog (
796+ 'https://sessionapp.zendesk.com/hc/sections/4416517450649-Support' ,
797+ dispatch
798+ ) ;
799+ } ,
800+ closeAfterClick : true ,
801+ } ,
802+ {
803+ label : { token : 'close' } ,
804+ dataTestId : 'modal-close-button' ,
805+ closeAfterClick : true ,
806+ } ,
807+ ] ,
808+ } )
809+ ) ;
815810 } , [ dispatch , fetchRecoverAccess ] ) ;
816811
817812 if ( ! userHasExpiredPro ) {
@@ -908,14 +903,18 @@ function PageHero() {
908903 overrideButtons : backendErrorButtons ,
909904 } )
910905 ) ;
911- } else if ( isLoading ) {
906+ return ;
907+ }
908+
909+ if ( isLoading ) {
912910 dispatch (
913911 updateLocalizedPopupDialog ( {
914912 title : { token : 'proStatusLoading' } ,
915913 description : { token : 'proStatusLoadingDescription' } ,
916914 } )
917915 ) ;
918916 }
917+ // Do nothing if not error or loading
919918 } , [ dispatch , isLoading , isError , backendErrorButtons ] ) ;
920919
921920 const heroStatusText = useMemo ( ( ) => {
0 commit comments