Skip to content

Commit

Permalink
Merge branch 'main' into HLM-1512
Browse files Browse the repository at this point in the history
# Conflicts:
#	tenant-portal/src/components/ManageSchemaHome/ManageSchemaHome.js
#	tenant-portal/src/components/SchemaAttributes/SchemaAttributes.js
  • Loading branch information
saiprakash-v committed Dec 30, 2022
2 parents 8c26090 + 8d293ee commit bb120b9
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 25 deletions.
2 changes: 2 additions & 0 deletions tenant-portal/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"uploadTemplate": "Upload Template",
"templateUploadSuccess": "Template Uploaded Successfully!",
"templateUploadFailed": "Template Failed to Upload!",
"deleteTemplateSuccess": "Template Deleted Successfully!",
"deleteTemplateFailed": "Failed to Delete Template",
"manageTemplate": "Manage Uploaded Templates"
},
"schemaDetails": {
Expand Down
2 changes: 2 additions & 0 deletions tenant-portal/public/locales/hi/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"uploadTemplate": "टेम्प्लेट अपलोड करें",
"templateUploadSuccess": "टेम्प्लेट सफलतापूर्वक अपलोड किया गया!",
"templateUploadFailed": "टेम्प्लेट अपलोड करने में विफल!",
"deleteTemplateSuccess": "टेम्प्लेट सफलतापूर्वक हटा दिया गया था!",
"deleteTemplateFailed": "टेम्प्लेट हटाने में विफल",
"manageTemplate": "अपलोड किए गए टेम्प्लेट प्रबंधित करें"
},
"schemaDetails": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ const ManageSchemaHome = () => {
</div>
</div>}
{ !schemaClicked && <div><hr/>
<Row gutter='3' xs={1} sm={2} md={3} className="justify-content-end">
<Row gutter='3' xs={1} sm={2} md={5} className="justify-content-end">
<Col className="my-1 h-100">
<Link to={`${config.urlPath}/manage-schema/view-inbuilt-attributes`} >
<GenericButton img='' text={t('noSchemaPage.viewAttributesBtn')} variant='outline-primary' />
Expand Down
44 changes: 32 additions & 12 deletions tenant-portal/src/components/ManageTempModal/ManageTempModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import config from '../../config.json';
import { getToken } from '../../utils/keycloak';
const axios = require('axios');

const ManageTempModal = ({schemaBody, setShowModal}) => {
const ManageTempModal = ({schemaBody, setShowModal, showToast}) => {
var dupSchemaBody = {...schemaBody};
const [changeSchema, setChangeSchema] = useState(dupSchemaBody);
var schema = JSON.parse(changeSchema.schema);
Expand All @@ -30,30 +30,50 @@ const ManageTempModal = ({schemaBody, setShowModal}) => {
document.body.appendChild(element); // Required for this to work in FireFox
element.click();
}
var requestBody;
const delTemplate = async (key) => {
const userToken = await getToken();
delete dupTemp[key];
dupSchemaBody.schema = JSON.stringify(schema)
setChangeSchema(dupSchemaBody)
axios.put(`${config.schemaUrl}/${schemaBody.osid}`, changeSchema, {headers:{"Authorization" :`Bearer ${userToken}`}})
.then(res => res.data)
var dummyTemp = dupTemp
delete dummyTemp[key];
setDupTemp(dummyTemp);
schema._osConfig.certificateTemplates = dupTemp;
dupSchemaBody.schema = JSON.stringify(schema);
requestBody = {"name": schema.title,
"schema": dupSchemaBody.schema }
setChangeSchema(requestBody);
console.log(schemaBody);
axios.put(`${config.schemaUrl}/${schemaBody.osid.slice(2)}`, requestBody, {headers:{"Authorization" :`Bearer ${userToken}`}})
.then((res) => {
if(res?.data) {
showToast("DELETE_SUCCESS");
}
})
.catch(error => {
showToast("DELETE_FAILED");
console.error(error);
throw error;
});
return
}


const handleClose = () => {
setShow(false);
setShowModal(false);
setTimeout(() => {
window.location.reload()
}, 1500);

}
useEffect(() => {
setDupTemp(templates)
setDupTemp(JSON.parse(changeSchema.schema)._osConfig?.certificateTemplates)
}, [])



return (
<Modal show={show} onHide={null}>
<Modal.Header className='border-0'>
<Modal.Title>Upload Templates</Modal.Title>
<Modal.Title>Uploaded Templates</Modal.Title>
</Modal.Header>
<Modal.Body>
<Table>
Expand All @@ -66,16 +86,16 @@ const ManageTempModal = ({schemaBody, setShowModal}) => {
{Object.keys(dupTemp).map((templatekey, index) =>
(<tr key={index}>
<td>{index+1}.</td>
<td>{standardizeString(templatekey)}</td>
<td><div className='d-flex flex-wrap justify-content-around px-3'>
<td style={{color: "#6493E0"}}>{standardizeString(templatekey)}</td>
<td><div className='d-flex flex-wrap justify-content-around px-5'>
<div onClick={() => {delTemplate(templatekey)}} ><img src={DeleteIcon} /></div>
<div onClick={() => {downloadHtml(dupTemp[templatekey])}}><img src={DownloadIcon} /></div></div></td>
</tr>))}
</thead>
</Table>
</Modal.Body>
<Modal.Footer className='border-0'>
<div onClick={() => {setShow(false);setShowModal(false)}} style={{width: "30%"}} >
<div onClick={handleClose} style={{width: "30%"}} >
<GenericButton img="" text="Close" variant="primary" />
</div>
</Modal.Footer>
Expand Down
40 changes: 29 additions & 11 deletions tenant-portal/src/components/SchemaAttributes/SchemaAttributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function SchemaAttributes({schemaDetails, setschemaPreview, attributes, setUpdat
const [show, setShow] = useState(false);
const [showModal, setShowModal] = useState(false);
const [templateUploaded, setTemplateUploaded] = useState(false);
const [showDeletToast, setshowDeleteToast] = useState("");
const [toast,setToast] = useState("");
const osid = schemaDetails.osid;

Expand All @@ -45,6 +46,18 @@ function SchemaAttributes({schemaDetails, setschemaPreview, attributes, setUpdat
headerClassName={`${styles['toastHeaderFailed']} `} toastClass="w-100" toastContainerClass={`${styles['templateToast']} w-50`} />
</div>)
break;
case "DELETE_SUCCESS":
setToast(<div className="d-flex justify-content-center">
<ToastComponent header={<div className="d-flex gap-3"><img src={successCheckmark}/><div>{t('schemaAttributesPage.deleteTemplateSuccess')}</div></div>}
headerClassName={`${styles['toastHeaderSuccess']} `} toastClass="w-100" toastContainerClass={`${styles['templateToast']} w-50`} />
</div>)
break;
case "DELETE_FAILED":
setToast(<div className="d-flex justify-content-center">
<ToastComponent header={<div className="d-flex gap-3"><img src={failedAlert}/><div>{t('schemaAttributesPage.deleteTemplateFailed')}</div></div>}
headerClassName={`${styles['toastHeaderFailed']} `} toastClass="w-100" toastContainerClass={`${styles['templateToast']} w-50`} />
</div>)
break;
default: setToast("")
}
setTimeout(() => {setToast("")}, 3000);
Expand Down Expand Up @@ -118,23 +131,27 @@ function SchemaAttributes({schemaDetails, setschemaPreview, attributes, setUpdat
<Container>
<Stack gap={3}>
<Row className="justify-content-between align-items-center">
<Container className="col-6">
<Row className="title">{schemaDetails.name}</Row>
<Row>{schemaDetails.description}</Row>
<Container className="col-4">
<Row className="title">{props.name}</Row>
<Row>{props.description}</Row>
</Container>
<Row className="justify-content-end col-6">
<Col className={schemaDetails.schema && (schemaDetails.status === SCHEMA_STATUS.DRAFT) && JSON.parse(schemaDetails.schema)._osConfig?.certificateTemplates && Object.keys(JSON.parse(schemaDetails.schema)._osConfig?.certificateTemplates).length===0? 'd-none': '' } >
<div onClick={()=>{setShowModal(true);}}>
<GenericButton text={t('schemaAttributesPage.manageTemplate')} variant="outline-primary" /></div>
{showModal && <ManageTempModal setShowModal={setShowModal} schemaBody={schemaDetails}/>}
{props.status==="DRAFT" &&
<Row className="justify-content-end col-8" xs={2}>
<Col className={props.schema && (props.status === SCHEMA_STATUS.DRAFT) &&
JSON.parse(props.schema)?._osConfig && JSON.parse(props.schema)._osConfig?.certificateTemplates &&
Object.keys(JSON.parse(props.schema)._osConfig?.certificateTemplates).length===0? 'd-none': '' } >
<div onClick={()=>{setShowModal(true);}}>
<GenericButton text={t('schemaAttributesPage.manageTemplate')} variant="outline-primary border-0" /></div>
{showModal && <ManageTempModal setShowModal={setShowModal} schemaBody={props} showToast={showToast} />}

</Col>
<Col>
<div onClick={() => setShow(true)}>
<GenericButton text={t('schemaAttributesPage.uploadTemplate')} variant="primary"/>
<GenericButton text={t('schemaAttributesPage.uploadTemplate')} variant="outline-primary"/>
</div>
<UploadTemplate {...{show, setShow, osid, setTemplateUploaded,showToast}}/>
</Col>
</Row>
</Row> }
</Row>
<Row className="p-3 border overflow-auto d-xxl-inline-block">
<Row className="table-heading py-2">{t('schemaAttributesPage.fields')}</Row>
Expand Down Expand Up @@ -168,7 +185,8 @@ function SchemaAttributes({schemaDetails, setschemaPreview, attributes, setUpdat
</Container>

{toast}

{showDeletToast}

<hr className="mt-5 mb-3"/>
{ (schemaDetails.status === SCHEMA_STATUS.DRAFT || schemaDetails.status === SCHEMA_STATUS.INPROGRESS) &&
<Row gutter='3' xs={1} sm={2} md={4} className="justify-content-end pe-4" >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ function UploadTemplate(props){
});

props.setShow(false);
setTimeout(() => {
window.location.reload();
}, 1500);
}
return (
<>
Expand Down Expand Up @@ -86,7 +89,7 @@ function UploadTemplate(props){
</Modal.Body>
<Modal.Footer className="justify-content-center">
<Row className="w-100">
<Col><Button variant="outline-primary" onClick={() => {props.setShow(false)}}>
<Col><Button variant="outline-primary" onClick={() => {props.setShow(false);}}>
{t('templateUpload.close')}
</Button></Col>
<Col><Button variant="primary" onClick={saveTemplate}>
Expand Down

0 comments on commit bb120b9

Please sign in to comment.