1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-26 15:52:20 +01:00

103 lines
4.0 KiB
TypeScript
Raw Normal View History

2021-03-10 17:15:36 +01:00
/**
* Form to set the stripe's public and private keys
*/
2021-03-24 17:31:50 +01:00
import React, { ReactNode, useEffect, useState } from 'react';
2021-03-10 17:15:36 +01:00
import { Loader } from './loader';
import { useTranslation } from 'react-i18next';
import SettingAPI from '../api/setting';
import { SettingName } from '../models/setting';
2021-03-24 17:31:50 +01:00
import { FabInput } from './fab-input';
2021-03-10 17:15:36 +01:00
interface StripeKeysFormProps {
param: string
}
const stripeKeys = SettingAPI.query([SettingName.StripePublicKey, SettingName.StripeSecretKey]);
const StripeKeysFormComponent: React.FC<StripeKeysFormProps> = ({ param }) => {
const { t } = useTranslation('admin');
const [publicKey, setPublicKey] = useState<string>('');
2021-03-24 17:31:50 +01:00
const [publicKeyAddOn, setPublicKeyAddOn] = useState<ReactNode>(null);
const [publicKeyAddOnClassName, setPublicKeyAddOnClassName] = useState<string>('');
2021-03-10 17:15:36 +01:00
const [secretKey, setSecretKey] = useState<string>('');
2021-03-24 17:31:50 +01:00
const [secretKeyAddOn, setSecretKeyAddOn] = useState<ReactNode>(null);
const [secretKeyAddOnClassName, setSecretKeyAddOnClassName] = useState<string>('');
2021-03-10 17:15:36 +01:00
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
2021-03-24 17:31:50 +01:00
const testPublicKey = () => {
setPublicKeyAddOnClassName('key-valid');
setPublicKeyAddOn(<i className="fa fa-check" />);
}
2021-03-10 17:15:36 +01:00
return (
2021-03-24 17:31:50 +01:00
<div className="stripe-keys-form">
2021-03-10 17:15:36 +01:00
<div className="stripe-keys-info" dangerouslySetInnerHTML={{__html: t('app.admin.invoices.payment.stripe_keys_info_html')}} />
<form name="stripeKeysForm">
2021-03-24 17:31:50 +01:00
<div className="stripe-public-input">
<label htmlFor="stripe_public_key">{ t('app.admin.invoices.payment.public_key') } *</label>
<FabInput id="stripe_public_key"
icon={<i className="fa fa-info" />}
value={publicKey}
onChange={testPublicKey}
addOn={publicKeyAddOn}
addOnClassName={publicKeyAddOnClassName}
required />
<div className="key-input">
<span className="key-input__icon"><i className="fa fa-info" /></span>
2021-03-10 17:15:36 +01:00
<input type="text"
id="stripe_public_key"
value={publicKey}
ng-model-options='{ debounce: 200 }'
ng-change='testPublicKey()'
required />
<span className="input-group-addon"
ng-class="{'label-success': publicKeyStatus, 'label-danger text-white': !publicKeyStatus}"
ng-show="publicKeyStatus !== undefined && publicKey">
<i className="fa fa-times" ng-show="!publicKeyStatus" />
<i className="fa fa-check" ng-show="publicKeyStatus" />
</span>
</div>
</div>
2021-03-24 17:31:50 +01:00
<div className="stripe-secret-input">
<label htmlFor="stripe_secret_key">{ t('app.admin.invoices.payment.secret_key') } *</label>
<div className="key-input">
<span className="key-input__icon"><i className="fa fa-key" /></span>
2021-03-10 17:15:36 +01:00
<input type="text"
id="stripe_secret_key"
value={secretKey}
ng-model-options='{ debounce: 200 }'
ng-change='testSecretKey()'
required />
<span className="input-group-addon"
ng-class="{'label-success': secretKeyStatus, 'label-danger text-white': !secretKeyStatus}"
ng-show="secretKeyStatus !== undefined && secretKey">
<i className="fa fa-times" ng-show="!secretKeyStatus" />
<i className="fa fa-check" ng-show="secretKeyStatus" />
</span>
</div>
</div>
</form>
</div>
);
}
export const StripeKeysForm: React.FC<StripeKeysFormProps> = ({ param }) => {
return (
<Loader>
<StripeKeysFormComponent param={param} />
</Loader>
);
}