Skip to content
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

Feat/add settings modal to folder card #245

Merged
merged 9 commits into from
Nov 23, 2020
72 changes: 46 additions & 26 deletions src/components/FolderCard.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import PropTypes from 'prop-types';
import elementStyles from '../styles/isomer-cms/Elements.module.scss';
import contentStyles from '../styles/isomer-cms/pages/Content.module.scss';
import FolderModal from './FolderModal';

const FolderCard = ({
displayText,
Expand All @@ -13,38 +14,57 @@ const FolderCard = ({
siteName,
category,
}) => {
const [isFolderModalOpen, setIsFolderModalOpen] = useState(false)

const generateLink = () => {
if (isHomepage) return `/sites/${siteName}/homepage`
if (isCollection) return `/sites/${siteName}/collections/${category}`
return `/sites/${siteName}/resources/${category}`
}

return (
<Link className={`${contentStyles.component} ${contentStyles.card} ${elementStyles.folderCard}`} to={generateLink()}>
<div id={itemIndex} className={contentStyles.folderInfo}>
<i className={`bx bx-md text-dark ${isHomepage ? 'bxs-home-circle' : 'bxs-folder'} ${contentStyles.componentIcon}`} />
<span className={`${contentStyles.componentFolderName} align-self-center ml-4 mr-auto`}>{displayText}</span>
{
isHomepage
? ''
: (
<div className={contentStyles.componentIcon}>
<button
className={contentStyles.componentIcon}
type="button"
id={`settings-folder-${itemIndex}`}
onClick={(e) => {
e.preventDefault();
settingsToggle(e)}}
className={contentStyles.componentIcon}
>
<i id={`settingsIcon-${itemIndex}`} className="bx bx-dots-vertical-rounded" />
</button>
</div>
)
}
</div>
</Link>
<>
{
isFolderModalOpen
&& (
<FolderModal
displayTitle={isCollection ? 'Rename Collection' : 'Rename Resource Category'}
displayText={isCollection ? 'Collection name' : "Resource category name"}
onClose={() => setIsFolderModalOpen(false)}
category={category}
siteName={siteName}
isCollection={isCollection}
/>
)
}
<Link className={`${contentStyles.component} ${contentStyles.card} ${elementStyles.folderCard}`} to={generateLink()}>
<div id={itemIndex} className={contentStyles.folderInfo}>
<i className={`bx bx-md text-dark ${isHomepage ? 'bxs-home-circle' : 'bxs-folder'} ${contentStyles.componentIcon}`} />
<span className={`${contentStyles.componentFolderName} align-self-center ml-4 mr-auto`}>{displayText}</span>
{
isHomepage
? ''
: (
<div className={contentStyles.componentIcon}>
<button
className={contentStyles.componentIcon}
type="button"
id={`settings-folder-${itemIndex}`}
onClick={(e) => {
e.preventDefault();
settingsToggle(e);
setIsFolderModalOpen(true)
}}
className={contentStyles.componentIcon}
>
<i id={`settingsIcon-${itemIndex}`} className="bx bx-dots-vertical-rounded" />
</button>
</div>
)
}
</div>
</Link>
</>
)
}

Expand Down
67 changes: 67 additions & 0 deletions src/components/FolderModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { useState } from 'react';
import axios from 'axios';
import PropTypes from 'prop-types';
import elementStyles from '../styles/isomer-cms/Elements.module.scss';
import SaveDeleteButtons from './SaveDeleteButtons';
import FormField from './FormField';

// axios settings
axios.defaults.withCredentials = true

const FolderModal = ({ displayTitle, displayText, onClose, category, siteName, isCollection }) => {
const [newCategoryName, setNewCategoryName] = useState(category)

const folderNameChangeHandler = (event) => {
const { value } = event.target
setNewCategoryName(value)
}

const saveHandler = async () => {
try {
await axios.post(`${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/${isCollection ? 'collections' : 'resources'}/${category}/rename/${newCategoryName}`)
// Refresh page
window.location.reload();
} catch (err) {
console.log(err);
}
}

return (
<div className={elementStyles.overlay}>
<div className={elementStyles['modal-settings']}>
<div className={elementStyles.modalHeader}>
<h1>
{displayTitle}
</h1>
<button type="button" onClick={onClose}>
<i className="bx bx-x" />
</button>
</div>
<form className={elementStyles.modalContent}>
<FormField
title={displayText}
id="newCategoryName"
value={newCategoryName}
onFieldChange={folderNameChangeHandler}
/>
<div className={elementStyles.modalButtons}>
<SaveDeleteButtons
isDisabled={false}
hasDeleteButton={false}
saveCallback={saveHandler}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we align these to the right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 583bedc

/>
</div>
</form>
</div>
</div>
)
};

FolderModal.propTypes = {
displayTitle: PropTypes.string.isRequired,
displayText: PropTypes.string.isRequired,
onProceed: PropTypes.func.isRequired,
onCancel: PropTypes.func.isRequired,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These props are marked as isRequired but aren't defined on the component

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved in 697b4c7

};

export default FolderModal;