nested objects working on API piece

This commit is contained in:
Michael Ossig
2022-06-03 11:25:22 -04:00
parent ae6fdea025
commit ced673fdd6
6 changed files with 19 additions and 6 deletions

View File

@@ -8,7 +8,7 @@ export const Config = ({ configuration, descriptors, step, setActiveStep, action
const handleUpdateConfig: UpdateConfig = (item, value, current): void => {
let newConfig = { ...configuration };
console.log('UPDATE CONFIG PARAMS', item, value, newConfig);
console.log('UPDATE CONFIG PARAMS', item, value, current, newConfig);
if (value === null) {
delete newConfig[item];
} else if (current) {

View File

@@ -20,7 +20,7 @@ export const ConfigWrapper = () => {
const dispatch = useAppDispatch();
const updateStore = (value: any, action: any): void => {
const updateStore = (value: any, action: ActionCreatorWithPayload<any>): void => {
dispatch(action(value));
};

View File

@@ -1,3 +1,4 @@
import { ChangeEvent } from 'react';
import { Grid, Typography, TextField } from '@mui/material';
import { Descriptor, HandleInput } from '../types';
@@ -6,14 +7,24 @@ export interface OptionPropTypes {
onChange: HandleInput;
value: string;
isChecked: boolean;
current?: string;
}
export const Option = ({ descriptor, onChange, value, isChecked }: OptionPropTypes) => {
export const Option = ({ descriptor, onChange, value, isChecked, current }: OptionPropTypes) => {
return (
<Grid item xs={11}>
<Typography variant="overline">{descriptor.name}</Typography>
{/* <Typography variant="subtitle2">{descriptor.description}</Typography> */}
{isChecked && <TextField name={descriptor.name} onChange={onChange} id={descriptor.name} label={descriptor.name} value={value} fullWidth />}
{isChecked && (
<TextField
name={descriptor.name}
onChange={(e: ChangeEvent<HTMLInputElement>) => onChange(e, current)}
id={descriptor.name}
label={descriptor.name}
value={value}
fullWidth
/>
)}
</Grid>
);
};

View File

@@ -30,7 +30,7 @@ export const OptionWrapper = ({ descriptor, indexKey, value, addOrRemoveProp, ha
return (
isChecked && (
<Grid item xs={11} key={prop.name}>
<Option descriptor={prop} onChange={handleInput} value={value[prop.name]} isChecked={isChecked} />
<Option current={descriptor.name} descriptor={prop} onChange={handleInput} value={value[prop.name]} isChecked={isChecked} />
</Grid>
)
);

View File

@@ -2,6 +2,7 @@ import { Fragment, useState } from 'react';
import { FormControl, FormHelperText, Grid, InputLabel, MenuItem, Select, SelectChangeEvent, TextField, Typography } from '@mui/material';
import { NavButtons } from './NavButtons';
import type { OnDeckPropType } from '../../../app/types';
import type { ActionCreatorWithPayload } from '@reduxjs/toolkit';
interface ProfileFormProps {
configuration: OnDeckPropType;

View File

@@ -1,11 +1,12 @@
import { ChangeEvent } from 'react';
import type { Descriptor, OnDeckPropType } from '../../app/types';
import type { ActionCreatorWithPayload } from '@reduxjs/toolkit';
export interface ConfigPropTypes {
step: number;
configuration: OnDeckPropType;
descriptors: Descriptor[];
action: any;
action: ActionCreatorWithPayload<any>;
updateStore: (value: any, action: any) => void;
setActiveStep: (step: number) => void;
}