Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(integration): add ability to edit common fields
close #1434
- Loading branch information
1 parent
58369fb
commit fef660a
Showing
6 changed files
with
197 additions
and
5 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
src/modules/settings/integrations/components/common/CommonFieldForm.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import Button from 'modules/common/components/Button'; | ||
import FormControl from 'modules/common/components/form/Control'; | ||
import FormGroup from 'modules/common/components/form/Group'; | ||
import ControlLabel from 'modules/common/components/form/Label'; | ||
import { ModalFooter } from 'modules/common/styles/main'; | ||
import { __ } from 'modules/common/utils'; | ||
import React from 'react'; | ||
import SelectBrand from '../../containers/SelectBrand'; | ||
|
||
type Props = { | ||
integrationId: string; | ||
name: string; | ||
brandId: string; | ||
onSubmit: ( | ||
id: string, | ||
{ name, brandId }: { name: string; brandId: string } | ||
) => void; | ||
closeModal: () => void; | ||
}; | ||
|
||
type State = { | ||
name: string; | ||
brandId: string; | ||
}; | ||
|
||
class CommonFieldForm extends React.PureComponent<Props, State> { | ||
constructor(props: Props) { | ||
super(props); | ||
|
||
this.state = { | ||
name: props.name || '', | ||
brandId: props.brandId || '' | ||
}; | ||
} | ||
|
||
render() { | ||
const { integrationId, onSubmit, closeModal } = this.props; | ||
const { name, brandId } = this.state; | ||
|
||
const onBrandChange = e => { | ||
this.setState({ brandId: e.target.value }); | ||
}; | ||
|
||
const onNameBlur = e => { | ||
this.setState({ name: e.target.value }); | ||
}; | ||
|
||
const saveIntegration = e => { | ||
e.preventDefault(); | ||
|
||
onSubmit(integrationId, { name, brandId }); | ||
closeModal(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<FormGroup> | ||
<ControlLabel required={true}>{__('Name')}</ControlLabel> | ||
<FormControl | ||
required={true} | ||
defaultValue={name} | ||
onBlur={onNameBlur} | ||
autoFocus={true} | ||
/> | ||
</FormGroup> | ||
|
||
<SelectBrand | ||
isRequired={true} | ||
defaultValue={brandId} | ||
onChange={onBrandChange} | ||
/> | ||
<ModalFooter> | ||
<Button | ||
onClick={saveIntegration} | ||
type="submit" | ||
btnStyle="success" | ||
icon="checked-1" | ||
> | ||
{__('Save')} | ||
</Button> | ||
</ModalFooter> | ||
</> | ||
); | ||
} | ||
} | ||
|
||
export default CommonFieldForm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters