Skip to content

refactor!: component ObjectKeyModal #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/ObjectKeyModal/AddKeyRequest.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react'
import dispatcher from './../../helpers/dispatcher'
import ObjectAttributes from './../../stores/ObjectAttributes'
// global theme
import ObjectKeyModal from './ObjectKeyModal'
import { ObjectKeyModal } from './ObjectKeyModal'

// this input appears when adding a new value to an object
export default class extends React.PureComponent {
Expand All @@ -30,7 +30,7 @@ export default class extends React.PureComponent {
'new-key-request'
)
return (
input != '' &&
input !== '' &&
Object.keys(request.existing_value).indexOf(input) === -1
)
}
Expand Down
94 changes: 0 additions & 94 deletions src/components/ObjectKeyModal/ObjectKeyModal.jsx

This file was deleted.

80 changes: 80 additions & 0 deletions src/components/ObjectKeyModal/ObjectKeyModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React, { useState } from 'react'

import dispatcher from './../../helpers/dispatcher'
// global theme
import Theme from './../../themes/getStyle'
import { Add as Cancel, CheckCircle } from './../icons'

// this input appears when adding a new value to an object
export const ObjectKeyModal: React.FC<any> = ({ theme, isValid, rjvId, submit }) => {
const [input, setInput] = useState('')
const closeModal = () => {
dispatcher.dispatch({
rjvId,
name: 'RESET'
})
}

const handleSubmit = () => {
submit(input)
}

const valid = isValid(input)
return (
<div
className='key-modal-request'
{...Theme(theme, 'key-modal-request')}
onClick={closeModal}
>
<div
{...Theme(theme, 'key-modal')}
onClick={e => {
e.stopPropagation()
}}
>
<div {...Theme(theme, 'key-modal-label')}>Key Name:</div>
<div style={{ position: 'relative' }}>
<input
{...Theme(theme, 'key-modal-input')}
className='key-modal-input'
ref={el => el && el.focus()}
spellCheck={false}
value={input}
placeholder='...'
onChange={e => {
setInput(e.target.value)
}}
onKeyDown={e => {
if (valid && e.key === 'Enter') {
handleSubmit()
} else if (e.key === 'Escape') {
closeModal()
}
}}
/>
{valid
? (
<CheckCircle
{...Theme(theme, 'key-modal-submit')}
className='key-modal-submit'
onClick={() => handleSubmit()}
/>
)
: null}
</div>
<span {...Theme(theme, 'key-modal-cancel')}>
<Cancel
{...Theme(theme, 'key-modal-cancel-icon')}
className='key-modal-cancel'
onClick={() => {
dispatcher.dispatch({
rjvId,
name: 'RESET'
})
}}
/>
</span>
</div>
</div>
)
}