🎥 Make videos programmatically with React
Validate license key on WebRenderModal from Pro platform
Pramodde915bbd5d5b
diff --git a/packages/studio/src/components/RenderModal/WebRenderModalLicense.tsx b/packages/studio/src/components/RenderModal/WebRenderModalLicense.tsxindex 5cfd5a9eb1..529e5d776c 100644--- a/packages/studio/src/components/RenderModal/WebRenderModalLicense.tsx+++ b/packages/studio/src/components/RenderModal/WebRenderModalLicense.tsx@@ -9,6 +9,7 @@ import {Checkbox} from '../Checkbox';import {RemotionInput} from '../NewComposition/RemInput';import {ValidationMessage} from '../NewComposition/ValidationMessage';import {Spacing} from '../layout';+import {WebRenderModalLicenseKeyValidation} from './WebRenderModalLicenseKeyValidation';type WebRenderModalLicenseProps = {readonly licenseKey: string | null;@@ -257,6 +258,12 @@ export const WebRenderModalLicense: React.FC<WebRenderModalLicenseProps> = ({</div></>) : null}+ {licenseValidation.valid && licenseKey.length > 0 ? (+ <>+ <Spacing y={1} block />+ <WebRenderModalLicenseKeyValidation licenseKey={licenseKey} />+ </>+ ) : null}</div>) : null}{licenseKey === null ? (diff --git a/packages/studio/src/components/RenderModal/WebRenderModalLicenseKeyValidation.tsx b/packages/studio/src/components/RenderModal/WebRenderModalLicenseKeyValidation.tsxnew file mode 100644index 0000000000..3dea71ac1b--- /dev/null+++ b/packages/studio/src/components/RenderModal/WebRenderModalLicenseKeyValidation.tsx@@ -0,0 +1,86 @@+import React, {useEffect} from 'react';+import {LIGHT_TEXT} from '../../helpers/colors';++const textStyle: React.CSSProperties = {+ color: LIGHT_TEXT,+ fontSize: 14,+ fontFamily: 'sans-serif',+ lineHeight: 1.5,+};++const linkStyle: React.CSSProperties = {+ fontSize: 14,+ fontFamily: 'sans-serif',+ lineHeight: 1.5,+ cursor: 'pointer',+};++type WebRenderModalLicenseKeyValidationProps = {+ readonly licenseKey: string | null;+};++type LicenseKeyValidationResult = {+ readonly isValid: boolean;+ readonly hasActiveSubscription: boolean;+ readonly projectName: string;+ readonly projectSlug: string;+};++const PRO_HOST = 'http://localhost:3001';++export const WebRenderModalLicenseKeyValidation: React.FC<+ WebRenderModalLicenseKeyValidationProps+> = ({licenseKey}) => {+ const [isLoading, setIsLoading] = React.useState(false);+ const [validation, setValidation] =+ React.useState<LicenseKeyValidationResult | null>(null);++ useEffect(() => {+ if (licenseKey) {+ setIsLoading(true);+ setValidation(null);+ fetch(`${PRO_HOST}/api/validate-license-key`, {+ method: 'POST',+ body: JSON.stringify({+ licenseKey,+ }),+ headers: {+ 'Content-Type': 'application/json',+ },+ })+ .then((res) => res.json())+ .then((data) => {+ setValidation(data);+ setIsLoading(false);+ })+ .catch(() => {+ setValidation(null);+ });+ }+ }, [licenseKey]);++ return (+ <div style={textStyle}>+ {isLoading && 'Validating license key...'}+ {validation && !validation.isValid && '⚠️ Invalid license key'}+ {validation && validation.isValid && (+ <div>+ <span style={textStyle}>✅ {validation.projectName}. </span>+ {validation.hasActiveSubscription && (+ <span style={textStyle}>You have an active Company License. </span>+ )}+ <span style={textStyle}>+ Check your{' '}+ <a+ href={`${PRO_HOST}/projects/${validation.projectSlug}/usage#client-renders-usage`}+ target="_blank"+ style={linkStyle}+ >+ usage here+ </a>+ </span>+ </div>+ )}+ </div>+ );+};