generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #156 from bcgov/TICDI-319
Edit template
- Loading branch information
Showing
7 changed files
with
177 additions
and
2 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
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
111 changes: 111 additions & 0 deletions
111
frontend/src/app/components/modal/manage-templates/EditTemplateModal.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,111 @@ | ||
import { FC, useState } from 'react'; | ||
import Modal from 'react-bootstrap/Modal'; | ||
import { editTemplate, uploadTemplate } from '../../../common/manage-templates'; | ||
import { Button } from 'react-bootstrap'; | ||
|
||
type EditTemplateModalProps = { | ||
show: boolean; | ||
documentName: string; | ||
documentId: number; | ||
documentVersion: number; | ||
documentTypeId: number | ||
onHide: () => void; | ||
onUpload: () => void; | ||
}; | ||
|
||
const EditTemplateModal: FC<EditTemplateModalProps> = ({ | ||
show, | ||
documentName, | ||
documentId, | ||
documentVersion, | ||
documentTypeId, | ||
onHide, | ||
onUpload, | ||
}) => { | ||
const [error, setError] = useState(''); | ||
const [showError, setShowError] = useState(false); | ||
const [documentNameText, setDocumentNameText] = useState<string>(documentName); | ||
const [documentVersionText, setDocumentVersionText] = useState<string | number>(documentVersion); | ||
const [isLoading, setIsLoading] = useState<boolean>(false); | ||
|
||
const editButtonHandler = async () => { | ||
if (!documentNameText || !documentVersionText) { | ||
setError('Fields cannot be empty'); | ||
setShowError(true); | ||
return; | ||
} | ||
try { | ||
setIsLoading(true); | ||
setShowError(false); | ||
await editTemplate(documentId, documentTypeId, +documentVersionText, documentNameText); | ||
} catch (error) { | ||
setError('Error updating templete'); | ||
setShowError(true); | ||
console.log(error); | ||
} finally { | ||
setIsLoading(false); | ||
onUpload(); | ||
} | ||
}; | ||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
const value = e.target.value; | ||
if (value === '') { | ||
setDocumentVersionText(''); | ||
} else { | ||
setDocumentVersionText(+value); | ||
} | ||
}; | ||
|
||
return ( | ||
<Modal show={show} onHide={onHide} size="lg"> | ||
<Modal.Header> | ||
<Modal.Title>Edit Template</Modal.Title> | ||
<Button | ||
variant="none" | ||
onClick={onHide} | ||
style={{ | ||
marginLeft: 'auto', | ||
border: 'none', | ||
backgroundColor: 'transparent', | ||
color: 'black', | ||
}} | ||
> | ||
× | ||
</Button> | ||
</Modal.Header> | ||
<Modal.Body> | ||
|
||
<div style={{ margin: '10px' }}> | ||
<label style={{ fontWeight: 'bold', marginRight: '10px' }}>Doc No.</label> | ||
<input | ||
type="text" | ||
value={documentVersionText} | ||
onChange={handleChange} | ||
placeholder="Document Number" | ||
style={{ width: '500px' }} | ||
/> | ||
</div> | ||
<div style={{ margin: '10px' }}> | ||
<label style={{ fontWeight: 'bold', marginRight: '10px' }}>Template Name:</label> | ||
<input | ||
type="text" | ||
value={documentNameText} | ||
onChange={(e) => setDocumentNameText(e.target.value)} | ||
placeholder="Template Name" | ||
style={{ width: '500px' }} | ||
/> | ||
</div> | ||
{showError && <div className="alert alert-danger">{error}</div>} | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button variant="primary" onClick={editButtonHandler} disabled={(documentName == documentNameText) && (documentVersion == documentVersionText)}> | ||
Save | ||
</Button> | ||
<Button variant="secondary" onClick={onHide} > | ||
Cancel | ||
</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
); | ||
}; | ||
export default EditTemplateModal; |
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