import { __, _n, sprintf } from '@wordpress/i18n'; import React, { useEffect, useState } from 'react'; import { api, moduleRunning, env } from '../api'; import { Card, Button, Badge, Notice, PageState, ScoreRing } from '../components/ui'; import Explain from '../components/Explain'; /** * Licence status, and nothing more. * * Two backends can be authoritative here: * * backend.enforced === true Freemius runs licensing. It owns the key, the * seats, the renewals and the update channel, so * this screen only reports what it says and * links to the screens that change it. No key is * entered, stored or displayed here — the SDK's * own activation form and account page do that. * backend.enforced === false Freemius is not configured on this build (an * internal or development copy). The local * serial store stays in charge so the screen is * still usable, and says plainly that it is a * development mode. * * Nothing on this screen can break the plugin: every field is optional, every * value may be null, and a licence problem never hides data the customer has * already produced. */ /** One label/value row of the status table. */ function Row({ label, children, hint }) { return (
{label} {hint && {hint}} {children}
); } function FreemiusView({ backend, onReload }) { const licensed = !!backend.licensed; const connected = !!backend.connected; const grace = backend.graceDays; const expires = backend.expires ? String(backend.expires).slice(0, 10) : null; const sites = backend.siteLimit === null || backend.siteLimit === undefined ? 'Unlimited' : backend.siteLimit; const verdict = licensed ? { tone: 'good', badge: __('Licensed', 'ai-rank-suite'), title: sprintf(__('%s is active on this site.', 'ai-rank-suite'), backend.plan || 'AI Rank Suite Agency'), why: expires ? sprintf(__('Automatic updates are on and the licence renews on %s. Every Pro action — AI writing, the autopilot, answer simulation — is available.', 'ai-rank-suite'), expires) : 'Automatic updates are on and every Pro action is available.', } : grace !== null && grace !== undefined ? { tone: 'warning', badge: sprintf(_n('Grace period · %d day left', 'Grace period · %d days left', grace, 'ai-rank-suite'), grace), title: __('The licence server could not be reached, so the last known good licence still applies.', 'ai-rank-suite'), why: __('This bridges a temporary outage on our side, not an expired licence. If it persists past the grace period, Pro actions pause — your settings, reports and published output stay exactly as they are.', 'ai-rank-suite'), } : { tone: 'bad', // These four were bare strings, so the one screen a // customer opens when something is wrong with their // licence spoke English inside a German admin. badge: connected ? __('No active licence', 'ai-rank-suite') : __('Not activated', 'ai-rank-suite'), title: connected ? __('This site is connected but has no active licence.', 'ai-rank-suite') : __('This site has no licence activated yet.', 'ai-rank-suite'), why: __('Your settings, reports, schema, redirects and everything already published keep working and stay untouched. Only new Pro actions and automatic updates are paused until a licence is active.', 'ai-rank-suite'), }; return (
{backend.error && {backend.error}}
{verdict.badge}

{verdict.title}

{verdict.why}

{!licensed && backend.activateUrl && ( {__('Activate a licence', 'ai-rank-suite')} )} {backend.manageUrl && ( {licensed ? __('Manage licence and sites', 'ai-rank-suite') : __('Licence account', 'ai-rank-suite')} )} {/* * The one that actually asks Freemius. "Re-check now" * below only re-reads our own answer, which is why a * released version can stay invisible here for an hour * while that button reports everything is fine. This * forces the SDK to ask the server for the newest tag * and realigns its state — the fix after a manual ZIP * install, which replaces the files without the SDK's * updater ever running. */} {backend.syncUrl && ( {__('Check for a new version', 'ai-rank-suite')} )} {/* Same tab, no arrow: this is the plugin's own upgrade screen now, not an outbound link to Freemius' pricing page — which does not exist until the customer has opted in, and used to drop them on the WordPress dashboard. */} {!licensed && backend.pricingUrl && ( {__('See plans', 'ai-rank-suite')} )}
{licensed ? 'On' : 'Off'} {__('Automatic updates', 'ai-rank-suite')}
{sites} {__('Sites in this plan', 'ai-rank-suite')}
{backend.plan ? ( <> {backend.plan} {backend.isTrial ? ' · trial' : ''} ) : ( — )} {licensed ? ( {__('active', 'ai-rank-suite')} ) : grace !== null && grace !== undefined ? ( grace period ) : ( {__('inactive', 'ai-rank-suite')} )} {backend.isCancelled ? cancelled — runs to the end of the term : null} {backend.siteActive ? {__('activated', 'ai-rank-suite')} : {__('not activated', 'ai-rank-suite')}} {backend.sites !== null && backend.sites !== undefined ? ( {backend.sites} {backend.sites === 1 ? 'site' : 'sites'} using this licence {backend.siteLimit ? ' ' + sprintf(__('of %s', 'ai-rank-suite'), backend.siteLimit) : ' · ' + __('unlimited', 'ai-rank-suite')} ) : null} {expires || —} {backend.updates ? {__('enabled', 'ai-rank-suite')} : {__('paused', 'ai-rank-suite')}} {connected ? {__('connected', 'ai-rank-suite')} : {__('not connected', 'ai-rank-suite')}} {backend.userEmail ? {backend.userEmail} : null} {(backend.productId || backend.slug) && ( {[backend.productId ? `#${backend.productId}` : '', backend.slug || ''] .filter(Boolean) .join(' · ')} {backend.sdkVersion ? ` · SDK ${backend.sdkVersion}` : ''} )}
{__('Keeps working', 'ai-rank-suite')}
{__('Every published title, description, schema block, redirect, llms.txt and sitemap. All settings, scores, audits and reports. Nothing is deleted, hidden or switched off on the front end — a licence problem must never cost you rankings.', 'ai-rank-suite')}
{__('Pauses', 'ai-rank-suite')}
{__('New Pro actions — AI writing, the autopilot, answer simulation, keyword ideas — and automatic updates. They resume the moment a licence is active again.', 'ai-rank-suite')}

Your licence key, seats, invoices and renewals live in your account with our licensing provider (Freemius). This screen reads that state and links to it; it never stores a key of its own and never asks you to paste one anywhere else. Use {__('Manage licence and sites', 'ai-rank-suite')} to move a licence between sites, download invoices or cancel.

); } export default function License() { const [state, setState] = useState(null); const [error, setError] = useState(null); // The free edition carries no licensing module at all, so there is no // /license route to read: the tab says what this edition is and where Pro // is, instead of asking a route that does not exist and showing its 404. const hasLicensing = moduleRunning('licensing'); const load = () => api .get('/license') .then(setState) .catch((e) => setError(e.message)); useEffect(() => { if (hasLicensing) load(); }, [hasLicensing]); if (!hasLicensing) { return (
{__('Pro', 'ai-rank-suite')}

{__('This is the free edition from WordPress.org. It has no licence to manage: every feature in it is fully yours. The AI engine, the autopilot, answer simulation, rank tracking and the other Pro modules come with AI Rank Suite Pro, sold and updated through our own site.', 'ai-rank-suite')}

{__('See Pro', 'ai-rank-suite')}
); } if (!state) return ; // There is nothing to type here and nothing to submit. Freemius owns the // key, the plan, the trial and the renewal; this screen reads that state // and links to the screens that change it. The field that used to sit here // asked for a serial number in a format this plugin invented, stored it // locally, and validated it against nothing — a customer who had just paid // would have been shown a box for a key that does not exist. const backend = state.backend || state; if (backend.enforced) { return (
{error && {error}}
); } // A build whose Freemius credentials were never filled in. That is a // development copy, and it must not lock its own owner out: everything // runs, licensing simply is not switched on. return (
{error && {error}} {__('Development build.', 'ai-rank-suite')}{' '} {__('No licensing provider is configured, so nothing on this copy is gated. Licensing and automatic updates are switched off; every other feature works normally.', 'ai-rank-suite')}{' '} {__('A released build carries real credentials, and this screen then shows the licence state of the site.', 'ai-rank-suite')}

{__('Your licence key, seats, invoices, renewals and trials live in your account with Freemius. This plugin reads that state; it never keeps a key of its own, and there is nothing on this screen to fill in.', 'ai-rank-suite')}

); }