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

Edit tutorial title & summary #112

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
62 changes: 60 additions & 2 deletions src/components/Tutorials/subComps/EditControls.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ import InsertDriveFileIcon from "@mui/icons-material/InsertDriveFile";
import VisibilityOffIcon from "@mui/icons-material/VisibilityOff";
import FormatAlignLeftIcon from "@mui/icons-material/FormatAlignLeft";
import FormatPaintIcon from "@mui/icons-material/FormatPaint";
import TitleIcon from "@mui/icons-material/Title";
import UserList from "../../Editor/UserList";
import { publishUnpublishTutorial } from "../../../store/actions";
import { useFirebase, useFirestore } from "react-redux-firebase";
import { useDispatch } from "react-redux";
import RemoveStepModal from "./RemoveStepModal";
import ColorPickerModal from "./ColorPickerModal";
import { Box, Stack } from "@mui/system";
import Swal from "sweetalert2";
import { editTutorialSummary, editTutorialTitle } from "../../../store/actions";

const EditControls = ({
isPublished,
Expand Down Expand Up @@ -55,6 +58,57 @@ const EditControls = ({
setAnchorEl(null);
};

const editSummary = () => {
setAnchorEl(null);
Swal.fire({
title: "Edit Summary",
input: "textarea",
inputLabel: "Summary",
inputPlaceholder: "Enter Summary",
showCancelButton: true,
inputValidator: value => {
if (!value) {
return "You need to write something!";
}
}
}).then(async result => {
if (result.isConfirmed) {
console.log(result.value);
await editTutorialSummary(tutorial_id, owner, result.value)(
firebase,
firestore,
dispatch
);
Swal.fire("Saved!", "Summary has been updated.", "success");
}
});
};
const editTitle = () => {
setAnchorEl(null);
Swal.fire({
title: "Edit Title",
input: "text",
inputLabel: "Title",
inputPlaceholder: "Enter Title",
showCancelButton: true,
inputValidator: value => {
if (!value) {
return "You need to write something!";
}
}
}).then(async result => {
if (result.isConfirmed) {
console.log(result.value);
await editTutorialTitle(tutorial_id, owner, result.value)(
firebase,
firestore,
dispatch
);
Swal.fire("Saved!", "Title has been updated.", "success");
}
});
};

return (
<>
<Button
Expand Down Expand Up @@ -83,9 +137,13 @@ const EditControls = ({
transformOrigin={{ horizontal: "right", vertical: "top" }}
anchorOrigin={{ horizontal: "right", vertical: "bottom" }}
>
<MenuItem key="edit_description">
<FormatAlignLeftIcon /> Edit Description
<MenuItem key="edit_description" onClick={editSummary}>
<FormatAlignLeftIcon /> Edit Summary
</MenuItem>
<MenuItem key="edit_title" onClick={editTitle}>
<TitleIcon /> Edit Title
</MenuItem>

<MenuItem
key="edit_codeLabz_theme"
onClick={() => setViewColorPickerModal(true)}
Expand Down
4 changes: 3 additions & 1 deletion src/store/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,7 @@ export {
setTutorialTheme,
updateStepTime,
updateStepTitle,
uploadTutorialImages
uploadTutorialImages,
editTutorialSummary,
editTutorialTitle
} from "./tutorialsActions";
Loading