-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix snippet page bugs, Implement Snippet editing modal box
- Loading branch information
1 parent
340aa6e
commit 55656fe
Showing
11 changed files
with
207 additions
and
58 deletions.
There are no files selected for viewing
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
3 changes: 3 additions & 0 deletions
3
src/app/containers/Preference/Snippet/snippetInfoModal/components.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,3 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const OuterContainer = styled.div``; |
93 changes: 93 additions & 0 deletions
93
src/app/containers/Preference/Snippet/snippetInfoModal/index.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,93 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { | ||
Button, | ||
Modal, | ||
ModalHeader, | ||
ModalBody, | ||
ModalFooter, | ||
FormGroup, | ||
Input, | ||
Label, | ||
} from 'reactstrap'; | ||
import { OuterContainer } from './components'; | ||
import * as styles from './style'; | ||
import { snippetInfoChangeHandler } from '../utils'; | ||
|
||
type IProps = { | ||
opened: boolean; | ||
setOpened: (opened: boolean) => void; | ||
snippetInfo: SnippetItem; | ||
reloadSnippets: () => void; | ||
}; | ||
|
||
const SnippetInfoModal = (props: IProps) => { | ||
const { opened, setOpened, snippetInfo, reloadSnippets } = props; | ||
|
||
const toggle = () => setOpened(!opened); | ||
|
||
const [snippet, setSnippet] = useState<string>(''); | ||
|
||
useEffect(() => { | ||
if (snippetInfo.snippet) { | ||
setSnippet(snippetInfo.snippet); | ||
} else { | ||
setSnippet(''); | ||
} | ||
}, [snippetInfo]); | ||
|
||
const editSnippetInfo = () => { | ||
snippetInfoChangeHandler(snippetInfo, 'snippet', snippet).then(() => { | ||
reloadSnippets(); | ||
return null; | ||
}); | ||
}; | ||
|
||
const saveBtnHandler = () => { | ||
editSnippetInfo(); | ||
toggle(); | ||
}; | ||
|
||
return ( | ||
<OuterContainer> | ||
<Modal | ||
fade | ||
centered | ||
isOpen={opened} | ||
toggle={toggle} | ||
style={{ | ||
color: '#212529', | ||
minHeight: 500, | ||
}} | ||
> | ||
<ModalHeader toggle={toggle}>Edit snippet information</ModalHeader> | ||
<ModalBody> | ||
<FormGroup check> | ||
<Label check style={styles.labelStyle}> | ||
Snippet | ||
</Label> | ||
<Input | ||
name="text" | ||
type="textarea" | ||
value={snippet} | ||
onChange={(e) => setSnippet(e.target.value)} | ||
/> | ||
</FormGroup> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button | ||
style={styles.btnStyle} | ||
color="primary" | ||
onClick={saveBtnHandler} | ||
> | ||
Save | ||
</Button> | ||
<Button style={styles.btnStyle} color="secondary" onClick={toggle}> | ||
Cancel | ||
</Button> | ||
</ModalFooter> | ||
</Modal> | ||
</OuterContainer> | ||
); | ||
}; | ||
|
||
export default SnippetInfoModal; |
3 changes: 3 additions & 0 deletions
3
src/app/containers/Preference/Snippet/snippetInfoModal/style.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,3 @@ | ||
export const labelStyle = { width: '80%', marginBottom: 15 }; | ||
|
||
export const btnStyle = { fontSize: 14 }; |
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
Oops, something went wrong.