(props)
| 34 | } |
| 35 | |
| 36 | const VariationItem: React.FC<IProps> = (props) => { |
| 37 | const [ open, setOpen ] = useState<boolean>(false); |
| 38 | const [ canSave, setCanSave ] = useState<boolean>(true); |
| 39 | const [ jsonValue, setJsonValue ] = useState<string>(''); |
| 40 | const intl = useIntl(); |
| 41 | |
| 42 | const { |
| 43 | disabled, |
| 44 | total, |
| 45 | returnType, |
| 46 | item: { |
| 47 | value, |
| 48 | name, |
| 49 | description, |
| 50 | index, |
| 51 | id, |
| 52 | }, |
| 53 | prefix, |
| 54 | handleInput, |
| 55 | handleDelete, |
| 56 | handleChangeVariation, |
| 57 | hooksFormContainer, |
| 58 | ruleContainer, |
| 59 | defaultServeContainer |
| 60 | } = props; |
| 61 | |
| 62 | const { rules, saveRules } = ruleContainer.useContainer(); |
| 63 | const { defaultServe, saveDefaultServe } = defaultServeContainer.useContainer(); |
| 64 | |
| 65 | const { |
| 66 | formState: { errors }, |
| 67 | register, |
| 68 | unregister, |
| 69 | setValue, |
| 70 | trigger, |
| 71 | } = hooksFormContainer.useContainer(); |
| 72 | |
| 73 | useEffect(() => { |
| 74 | register(`variation_${id}_name`, { |
| 75 | required: { |
| 76 | value: true, |
| 77 | message: intl.formatMessage({id: 'common.input.placeholder'}) |
| 78 | } |
| 79 | }); |
| 80 | |
| 81 | if (returnType !== 'boolean') { |
| 82 | unregister(`variation_${id}_normal`); |
| 83 | register(`variation_${id}`, { |
| 84 | required: { |
| 85 | value: true, |
| 86 | message: intl.formatMessage({id: 'common.input.placeholder'}) |
| 87 | }, |
| 88 | validate: { |
| 89 | isNumber: (v: string) => { |
| 90 | const reg = /^(-?\d+)(\.\d+)?$/i; |
| 91 | if (v && returnType === 'number' && !reg.test(v)) { |
| 92 | return intl.formatMessage({id: 'common.number.invalid'}); |
| 93 | } |
nothing calls this directly
no test coverage detected