Skip to content

Commit

Permalink
submit functionality added
Browse files Browse the repository at this point in the history
  • Loading branch information
nikk15 committed Jul 28, 2023
1 parent 08adfcb commit 839b3a8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
31 changes: 12 additions & 19 deletions admin/src/react-components/ThemeBuilder/ThemeBuilder.tsx
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
import React, {useEffect, useState} from 'react';
import React, {useEffect, useMemo, useState} from 'react';
// import theme from "../../utils/sample-theme";
import {Button, Input, Select} from '@mozilla/lilypad-ui'

const ThemeBuilder = ({config}) => {
const themes = JSON.parse(config?.hubs?.theme?.themes)
const formattedThemes = themes.map(theme => ({title: theme.name, value: theme.id}));

const ThemeBuilder = ({config, onGlobalChange, onSave, path}) => {
const [themes, setThemes] =useState(JSON.parse(config?.hubs?.theme?.themes))
const [selectedTheme, setSelectedTheme] = useState(themes.find(theme => !!theme?.default))
const formattedThemes = useMemo(() => themes.map(theme => ({title: theme.name, value: theme.id})), [themes]);

const onChange = e => {
const onThemeSelect = e => {
setSelectedTheme(themes.find(theme => theme.id === e.target.value))
}

const onSubmit = e => {
e.preventDefault()
console.log(selectedTheme)
onSave(e)
setThemes(prevState => [...prevState.filter(theme => theme.id !== selectedTheme.id), selectedTheme])
}

const onVariableChange = (e, key )=> {
console.log(e.target.value, key)
e.preventDefault()
e.persist()
setSelectedTheme(prevState => {
console.log(prevState)
return {...prevState, variables: {...prevState.variables, [key]: e.target.value}}
})
setSelectedTheme(prevState => ({...prevState, variables: {...prevState.variables, [key]: e.target.value}}))
console.log([...themes.filter(theme => theme.id !== selectedTheme.id), {...selectedTheme, variables: {...selectedTheme.variables, [key]: e.target.value}}])
onGlobalChange(path, JSON.stringify([...themes.filter(theme => theme.id !== selectedTheme.id), {...selectedTheme, variables: {...selectedTheme.variables, [key]: e.target.value}}]))
}

useEffect(() => {
console.log(selectedTheme)
}, [selectedTheme])


return (
<div>
<Select label="Themes" options={formattedThemes} name="Themes" value={selectedTheme.id} onChange={onChange}/>
<Select label="Themes" options={formattedThemes} name="Themes" value={selectedTheme.id} onChange={onThemeSelect}/>
<form onSubmit={onSubmit} >
{Object.entries(selectedTheme.variables).map(([key, value]) => {
return <Input label={key} name={key} value={value} onChange={e => onVariableChange(e, key)}/>
Expand Down
6 changes: 4 additions & 2 deletions admin/src/react-components/service-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class ConfigurationEditor extends Component {

onSubmit(e) {
e.preventDefault();

Check failure on line 211 in admin/src/react-components/service-editor.js

View workflow job for this annotation

GitHub Actions / test-and-deploy-storybook

Delete `····`
this.setState({ saving: true }, async () => {
try {
for (const [service, config] of Object.entries(this.state.config)) {
Expand Down Expand Up @@ -430,8 +430,10 @@ class ConfigurationEditor extends Component {
const configurables = this.getFilteredDescriptors(theme);
const getInput = ([path, descriptor]) => this.renderConfigurable(path, descriptor, getConfigValue(config, path));


Check failure on line 433 in admin/src/react-components/service-editor.js

View workflow job for this annotation

GitHub Actions / test-and-deploy-storybook

Replace `⏎⏎····return·(` with `····return·(⏎······`

return (<>
<ThemeBuilder config={config}/>
<ThemeBuilder config={config} onGlobalChange={this.onChange.bind(this)} onSave={this.onSubmit.bind(this)} path={configurables[2][0]}/>

Check failure on line 436 in admin/src/react-components/service-editor.js

View workflow job for this annotation

GitHub Actions / test-and-deploy-storybook

Replace `····<ThemeBuilder·config={config}·onGlobalChange={this.onChange.bind(this)}·onSave={this.onSubmit.bind(this)}·path={configurables[2][0]}` with `········<ThemeBuilder⏎··········config={config}⏎··········onGlobalChange={this.onChange.bind(this)}⏎··········onSave={this.onSubmit.bind(this)}⏎··········path={configurables[2][0]}⏎········`
<form onSubmit={this.onSubmit.bind(this)}>

Check failure on line 437 in admin/src/react-components/service-editor.js

View workflow job for this annotation

GitHub Actions / test-and-deploy-storybook

Replace `······` with `········`
<h3 className="heading-sm mb-24">Nametags</h3>

Check failure on line 438 in admin/src/react-components/service-editor.js

View workflow job for this annotation

GitHub Actions / test-and-deploy-storybook

Insert `··`
{getInput(configurables[0])}

Check failure on line 439 in admin/src/react-components/service-editor.js

View workflow job for this annotation

GitHub Actions / test-and-deploy-storybook

Insert `··`
Expand Down

0 comments on commit 839b3a8

Please sign in to comment.