BrandingPage.js
1 month ago
ContributePage.js
1 month ago
CustomCssPage.js
1 month ago
LicensePage.js
1 month ago
MediaHubPage.js
1 month ago
PresetsPage.js
1 month ago
UninstallPage.js
1 month ago
ViewingAnalyticsPage.js
1 month ago
LicensePage.js
150 lines
| 1 | import { __ } from '@wordpress/i18n'; |
| 2 | import { useState } from 'react'; |
| 3 | import { Button, Container, Input, Label, Text, toast } from '@bsf/force-ui'; |
| 4 | import SettingsPageShell from '../shared/SettingsPageShell'; |
| 5 | import SectionCard from '../shared/SectionCard'; |
| 6 | import ConfirmDialog from '../shared/ConfirmDialog'; |
| 7 | import useLicenseSettings from '../../../hooks/useLicenseSettings'; |
| 8 | import useRegisterActivePage from '../../../hooks/useRegisterActivePage'; |
| 9 | |
| 10 | const LicensePage = ( { registerActivePage } ) => { |
| 11 | const { |
| 12 | isLoading, |
| 13 | isActivating, |
| 14 | isDeactivating, |
| 15 | isActive, |
| 16 | licenseKey: savedLicenseKey, |
| 17 | activate, |
| 18 | deactivate, |
| 19 | } = useLicenseSettings(); |
| 20 | |
| 21 | const [ licenseKey, setLicenseKey ] = useState( '' ); |
| 22 | const [ confirmDeactivateOpen, setConfirmDeactivateOpen ] = useState( false ); |
| 23 | |
| 24 | useRegisterActivePage( registerActivePage, { |
| 25 | isDirty: false, |
| 26 | save: null, |
| 27 | discard: null, |
| 28 | } ); |
| 29 | |
| 30 | const handleActivate = async () => { |
| 31 | if ( ! licenseKey.trim() ) { |
| 32 | toast.error( __( 'Please enter a license key.', 'presto-player' ) ); |
| 33 | return; |
| 34 | } |
| 35 | try { |
| 36 | const data = await activate( licenseKey.trim() ); |
| 37 | setLicenseKey( '' ); |
| 38 | toast.success( |
| 39 | data.message || __( 'License activated successfully.', 'presto-player' ) |
| 40 | ); |
| 41 | // Pro PHP components only register on the next request, and |
| 42 | // `window.prestoPlayer.isPremium` is captured as a module-level |
| 43 | // const in many dashboard files — a reload is the cleanest way |
| 44 | // to bring the whole dashboard up in the licensed state. |
| 45 | setTimeout( () => window.location.reload(), 600 ); |
| 46 | } catch ( err ) { |
| 47 | toast.error( |
| 48 | err.message || __( 'Could not activate license.', 'presto-player' ) |
| 49 | ); |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | const handleDeactivate = async () => { |
| 54 | try { |
| 55 | const data = await deactivate(); |
| 56 | setConfirmDeactivateOpen( false ); |
| 57 | toast.success( |
| 58 | data.message || __( 'License deactivated.', 'presto-player' ) |
| 59 | ); |
| 60 | setTimeout( () => window.location.reload(), 600 ); |
| 61 | } catch ( err ) { |
| 62 | setConfirmDeactivateOpen( false ); |
| 63 | toast.error( |
| 64 | err.message || __( 'Could not deactivate license.', 'presto-player' ) |
| 65 | ); |
| 66 | } |
| 67 | }; |
| 68 | |
| 69 | const placeholderText = isActive |
| 70 | ? __( 'Your license is activated', 'presto-player' ) |
| 71 | : __( 'Paste your license key here', 'presto-player' ); |
| 72 | |
| 73 | return ( |
| 74 | <SettingsPageShell |
| 75 | title={ __( 'License', 'presto-player' ) } |
| 76 | isLoading={ isLoading } |
| 77 | > |
| 78 | <SectionCard> |
| 79 | <Container direction="column" className="gap-2"> |
| 80 | <Label size="sm">{ __( 'License Key', 'presto-player' ) }</Label> |
| 81 | <Container direction="column" className="gap-3 md:flex-row w-full"> |
| 82 | <Container.Item grow={ 1 } shrink={ 1 } className="w-full"> |
| 83 | <Input |
| 84 | type="text" |
| 85 | size="md" |
| 86 | placeholder={ placeholderText } |
| 87 | value={ isActive ? savedLicenseKey : licenseKey } |
| 88 | disabled={ isActive } |
| 89 | onChange={ setLicenseKey } |
| 90 | className="w-full" |
| 91 | /> |
| 92 | </Container.Item> |
| 93 | { isActive ? ( |
| 94 | <Button |
| 95 | variant="outline" |
| 96 | destructive |
| 97 | onClick={ () => setConfirmDeactivateOpen( true ) } |
| 98 | disabled={ isDeactivating } |
| 99 | > |
| 100 | { __( 'Deactivate', 'presto-player' ) } |
| 101 | </Button> |
| 102 | ) : ( |
| 103 | <Button |
| 104 | variant="primary" |
| 105 | onClick={ handleActivate } |
| 106 | disabled={ isActivating || ! licenseKey } |
| 107 | loading={ isActivating } |
| 108 | > |
| 109 | { __( 'Activate', 'presto-player' ) } |
| 110 | </Button> |
| 111 | ) } |
| 112 | </Container> |
| 113 | <Text size="xs" className="text-text-tertiary"> |
| 114 | { __( |
| 115 | 'Enter the License Key you received when you purchased this product. If you lost the key, you can retrieve it from', |
| 116 | 'presto-player' |
| 117 | ) }{ ' ' } |
| 118 | <Text |
| 119 | as="a" |
| 120 | size="xs" |
| 121 | href="https://my.prestomade.com/my-account/" |
| 122 | target="_blank" |
| 123 | rel="noreferrer" |
| 124 | className="text-brand-primary-600 hover:underline" |
| 125 | > |
| 126 | { __( 'My Account', 'presto-player' ) } |
| 127 | </Text> |
| 128 | </Text> |
| 129 | </Container> |
| 130 | </SectionCard> |
| 131 | |
| 132 | <ConfirmDialog |
| 133 | open={ confirmDeactivateOpen } |
| 134 | title={ __( 'Deactivate license?', 'presto-player' ) } |
| 135 | description={ __( |
| 136 | 'You will lose access to Pro features, automatic updates, and support on this site until you reactivate.', |
| 137 | 'presto-player' |
| 138 | ) } |
| 139 | confirmLabel={ __( 'Deactivate', 'presto-player' ) } |
| 140 | cancelLabel={ __( 'Cancel', 'presto-player' ) } |
| 141 | confirmDestructive |
| 142 | onConfirm={ handleDeactivate } |
| 143 | onCancel={ () => setConfirmDeactivateOpen( false ) } |
| 144 | /> |
| 145 | </SettingsPageShell> |
| 146 | ); |
| 147 | }; |
| 148 | |
| 149 | export default LicensePage; |
| 150 |