🎥 Make videos programmatically with React
Remove hook
Pramodcd9f696e012b
diff --git a/packages/studio/src/components/RenderModal/WebRenderModalLicense.tsx b/packages/studio/src/components/RenderModal/WebRenderModalLicense.tsxindex 6828e30590..f846d8d4ed 100644--- a/packages/studio/src/components/RenderModal/WebRenderModalLicense.tsx+++ b/packages/studio/src/components/RenderModal/WebRenderModalLicense.tsx@@ -1,4 +1,4 @@-import React, {useCallback, useMemo} from 'react';+import React, {useCallback, useEffect, useState} from 'react';import {BLUE,INPUT_BACKGROUND,@@ -11,8 +11,8 @@ import {ValidationMessage} from '../NewComposition/ValidationMessage';import {Spacing} from '../layout';import type {LicenseKeyDetails} from './WebRenderModalLicenseKeyDetails';import {- useLicenseKeyDetails,WebRenderModalLicenseKeyDetails,+ fetchLicenseKeyDetails,} from './WebRenderModalLicenseKeyDetails';type WebRenderModalLicenseProps = {@@ -113,10 +113,7 @@ type LicenseKeyValidation = {details: LicenseKeyDetails | null;};-const validateLicenseKey = (- key: string,- details: LicenseKeyDetails | null,-): LicenseKeyValidation => {+const validateLicenseKey = (key: string): LicenseKeyValidation => {if (key.length === 0) {return {valid: false, message: null, details: null};}@@ -147,22 +144,6 @@ const validateLicenseKey = (};}- if (details && !details.isValid) {- return {- valid: false,- message: 'License key is invalid or has been reset',- details: null,- };- }-- if (details?.isValid) {- return {- valid: true,- message: null,- details,- };- }-return {valid: true, message: null, details: null};};@@ -171,8 +152,48 @@ export const WebRenderModalLicense: React.FC<WebRenderModalLicenseProps> = ({setLicenseKey,initialPublicLicenseKey,}) => {- const {details: licenseKeyDetails, isLoading} =- useLicenseKeyDetails(licenseKey);+ const [licenseValidation, setLicenseValidation] =+ useState<LicenseKeyValidation>({valid: true, message: null, details: null});+ const [isLoading, setIsLoading] = useState(false);++ useEffect(() => {+ if (licenseKey === null || licenseKey === 'free-license') {+ return setLicenseValidation({+ valid: true,+ message: null,+ details: null,+ });+ }++ const validation = validateLicenseKey(licenseKey);+ if (!validation.valid) {+ return setLicenseValidation(validation);+ }++ setLicenseValidation({valid: true, message: null, details: null});+ setIsLoading(true);+ fetchLicenseKeyDetails(licenseKey)+ .then((details) => {+ setIsLoading(false);+ if (details.isValid) {+ setLicenseValidation({valid: true, message: null, details});+ } else {+ setLicenseValidation({+ valid: false,+ message: 'License key is invalid or has been reset',+ details: null,+ });+ }+ })+ .catch(() => {+ setIsLoading(false);+ setLicenseValidation({+ valid: false,+ message: 'Failed to fetch license key details',+ details: null,+ });+ });+ }, [licenseKey]);const onFreeLicenseChange = useCallback(() => {setLicenseKey('free-license');@@ -190,14 +211,6 @@ export const WebRenderModalLicense: React.FC<WebRenderModalLicenseProps> = ({[setLicenseKey],);- const licenseValidation = useMemo(() => {- if (licenseKey === null || licenseKey === 'free-license') {- return {valid: true, message: null, details: null};- }-- return validateLicenseKey(licenseKey, licenseKeyDetails);- }, [licenseKey, licenseKeyDetails]);-return (<div style={tabContainer}><div style={descriptionStyle}>diff --git a/packages/studio/src/components/RenderModal/WebRenderModalLicenseKeyDetails.tsx b/packages/studio/src/components/RenderModal/WebRenderModalLicenseKeyDetails.tsxindex 456d225285..643589cdc0 100644--- a/packages/studio/src/components/RenderModal/WebRenderModalLicenseKeyDetails.tsx+++ b/packages/studio/src/components/RenderModal/WebRenderModalLicenseKeyDetails.tsx@@ -1,4 +1,4 @@-import React, {useEffect} from 'react';+import React from 'react';import {LIGHT_TEXT} from '../../helpers/colors';import {CheckCircleFilled} from '../../icons/check-circle-filled';@@ -37,55 +37,32 @@ export type LicenseKeyDetails = {readonly projectSlug: string;};-type UseLicenseKeyDetailsState = {- readonly isLoading: boolean;- readonly details: LicenseKeyDetails | null;-};-type WebRenderModalLicenseKeyDetailsProps = {readonly details: LicenseKeyDetails;};const PRO_HOST = 'https://remotion.pro';-export const useLicenseKeyDetails = (- licenseKey: string | null,-): UseLicenseKeyDetailsState => {- const [isLoading, setIsLoading] = React.useState(false);- const [details, setDetails] = React.useState<LicenseKeyDetails | null>(null);-- useEffect(() => {- if (licenseKey) {- setIsLoading(true);- setDetails(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) => {- setDetails(data);- setIsLoading(false);- })- .catch(() => {- setDetails(null);- });- }- }, [licenseKey]);-- return {isLoading, details};+export const fetchLicenseKeyDetails = async (+ licenseKey: string,+): Promise<LicenseKeyDetails> => {+ const response = await fetch(`${PRO_HOST}/api/validate-license-key`, {+ method: 'POST',+ body: JSON.stringify({+ licenseKey,+ }),+ headers: {+ 'Content-Type': 'application/json',+ },+ });+ return response.json();};export const WebRenderModalLicenseKeyDetails: React.FC<WebRenderModalLicenseKeyDetailsProps> = ({details}) => {return (- <div>+ <><div style={bulletStyle}><CheckCircleFilled style={{...icon, fill: LIGHT_TEXT}} /><div style={textStyle}>@@ -107,12 +84,13 @@ export const WebRenderModalLicenseKeyDetails: React.FC<</a></div></div>+{details.hasActiveSubscription && (<div style={bulletStyle}><CheckCircleFilled style={{...icon, fill: LIGHT_TEXT}} /><div style={textStyle}>Active Company License</div></div>)}- </div>+ </>);};