/** * Form to set the stripe's public and private keys */ import React, { ReactNode, useEffect, useState } from 'react'; import { Loader } from './loader'; import { useTranslation } from 'react-i18next'; import SettingAPI from '../api/setting'; import { SettingName } from '../models/setting'; import { FabInput } from './fab-input'; interface StripeKeysFormProps { param: string } const stripeKeys = SettingAPI.query([SettingName.StripePublicKey, SettingName.StripeSecretKey]); const StripeKeysFormComponent: React.FC = ({ param }) => { const { t } = useTranslation('admin'); const [publicKey, setPublicKey] = useState(''); const [publicKeyAddOn, setPublicKeyAddOn] = useState(null); const [publicKeyAddOnClassName, setPublicKeyAddOnClassName] = useState(''); const [secretKey, setSecretKey] = useState(''); const [secretKeyAddOn, setSecretKeyAddOn] = useState(null); const [secretKeyAddOnClassName, setSecretKeyAddOnClassName] = useState(''); useEffect(() => { const keys = stripeKeys.read(); setPublicKey(keys.get(SettingName.StripePublicKey)); setSecretKey(keys.get(SettingName.StripeSecretKey)); }, []); // see StripeKeysModalController // from app/frontend/src/javascript/controllers/admin/invoices.js const testPublicKey = () => { setPublicKeyAddOnClassName('key-valid'); setPublicKeyAddOn(); } return (
} value={publicKey} onChange={testPublicKey} addOn={publicKeyAddOn} addOnClassName={publicKeyAddOnClassName} required />
); } export const StripeKeysForm: React.FC = ({ param }) => { return ( ); }