clean up and extra fields

This commit is contained in:
gingervitis 2021-01-03 04:10:08 -08:00 committed by Gabe Kangas
parent f385233109
commit f19dba31da
3 changed files with 15 additions and 22 deletions

View file

@ -1,21 +1,4 @@
/*
- auto saves ,ajax call (submit when blur or onEnter)
- set default text
- show error state/confirm states
- show info
- label
- min/max length
- populate with curren val (from local sstate)
load page,
get all config vals,
save to local state/context.
read vals from there.
update vals to state, andthru api.
*/
import React, { useState, useContext } from 'react';
import { Button, Form, Input, InputNumber } from 'antd';
import { FormItemProps } from 'antd/es/form';
@ -51,6 +34,8 @@ export default function TextField(props: TextFieldProps) {
handleResetValue,
initialValues = {},
onSubmit,
onBlur,
onChange,
type,
} = props;
@ -92,6 +77,10 @@ export default function TextField(props: TextFieldProps) {
setHasChanged(true);
setFieldValueForSubmit(val);
}
// if an extra onChange handler was sent in as a prop, let's run that too.
if (onChange) {
onChange();
}
};
// if you blur a required field with an empty value, restore its original value
@ -100,12 +89,16 @@ export default function TextField(props: TextFieldProps) {
if (required && val === '') {
handleResetValue(fieldName);
}
// if an extra onBlur handler was sent in as a prop, let's run that too.
if (onBlur) {
onBlur();
}
};
// how to get current value of input
const handleSubmit = async () => {
if ((required && fieldValueForSubmit !== '') || fieldValueForSubmit !== initialValue) {
// postUpdateToAPI(fieldValueForSubmit);
setSubmitStatus('validating');
await postConfigUpdateToAPI({

View file

@ -1,7 +1,7 @@
import React, { useContext, useEffect } from 'react';
import { Typography, Form } from 'antd';
import TextField, { TEXTFIELD_TYPE_NUMBER, TEXTFIELD_TYPE_PASSWORD, TEXTFIELD_TYPE_TEXTAREA } from './components/config/form-textfield';
import TextField, { TEXTFIELD_TYPE_NUMBER, TEXTFIELD_TYPE_PASSWORD } from './components/config/form-textfield';
import { ServerStatusContext } from '../utils/server-status-context';
import { TEXTFIELD_DEFAULTS } from './components/config/constants';

View file

@ -1,7 +1,7 @@
// TS types for elements on the Config pages
export interface TextFieldProps {
handleResetValue?: (fieldName) => void;
handleResetValue?: (fieldName: string) => void;
fieldName: string;
initialValues?: any;
type?: string;
@ -27,8 +27,8 @@ export interface UpdateArgs {
export interface ApiPostArgs {
apiPath: string,
data: object,
onSuccess?: (arg: any) => {},
onError?: (arg: any) => {},
onSuccess?: (arg: any) => void,
onError?: (arg: any) => void,
}
export interface ConfigDirectoryFields {