import React, { useEffect, useState } from "react"; import { EmailConfig, MfwConfig, PfwConfig, SmsConfig } from "../../../entities/Passport"; import { EntityDict } from "../../../oak-app-domain"; import { Switch, Form, Input, Select, Space, Tag } from 'antd'; import Styles from './web.module.less'; export default function Sms(props: { passport: EntityDict['passport']['OpSchema'] & { stateColor: string }; t: (k: string, params?: any) => string; changeEnabled: (enabled: boolean) => void; updateConfig: (id: string, config: SmsConfig | EmailConfig | PfwConfig | MfwConfig, path: string, value: any, type?: string) => void; }) { const { passport, t, changeEnabled, updateConfig } = props; const { id, type, enabled, stateColor } = passport; const config = passport.config as SmsConfig || {}; const [templateName, setTemplateName] = useState(config?.templateName || ''); const [smsCodeDuration, setSmsCodeDuration] = useState(config?.codeDuration || ''); const [smsDigit, setSmsDigit] = useState(config?.digit || ''); useEffect(() => { setTemplateName(config?.templateName || ''); setSmsCodeDuration(config?.codeDuration || ''); setSmsDigit(config?.digit || ''); }, [config]); return (
{t(`passport:v.type.${type}`)} { changeEnabled(checked) }} />
{enabled &&
{ updateConfig(id, config!, 'mockSend', checked, 'sms'); }} /> <> { setTemplateName(e.target.value); }} onBlur={() => { if (templateName !== (config as SmsConfig)?.templateName) { updateConfig(id, config!, 'templateName', templateName, 'sms'); } }} /> { const val = e.target.value; if (val) { setSmsCodeDuration(Number(val)); } else { setSmsCodeDuration(''); } }} onBlur={() => { if (Number(smsCodeDuration) > 0) { updateConfig(id, config!, 'codeDuration', smsCodeDuration, 'sms'); } else { updateConfig(id, config!, 'codeDuration', undefined, 'sms'); } }} suffix="分钟" /> { const val = e.target.value; if (val) { setSmsDigit(Number(val)); } else { setSmsDigit(''); } }} onBlur={() => { if (Number(smsDigit) > 0) { updateConfig(id, config!, 'digit', smsDigit, 'sms'); } else { updateConfig(id, config!, 'digit', undefined, 'sms'); } }} />
}
) }