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

Innovation day - Initial share project workflow #702

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions src/components/ProjectBar/ProjectBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import DownloadIcon from "../../assets/icons/download.svg";
import ProjectName from "../ProjectName/ProjectName";
import DownloadButton from "../DownloadButton/DownloadButton";
import SaveButton from "../SaveButton/SaveButton";
import ShareButton from "../ShareButton/ShareButton";

const ProjectBar = () => {
const { t } = useTranslation();
Expand Down Expand Up @@ -38,6 +39,9 @@ const ProjectBar = () => {
<div className="project-bar__btn-wrapper">
<SaveButton className="project-bar__btn btn--save" />
</div>
<div className="project-bar__btn-wrapper">
<ShareButton className="project-bar__btn btn--save" />
</div>
{lastSavedTime && user ? (
<SaveStatus saving={saving} lastSavedTime={lastSavedTime} />
) : null}
Expand Down
50 changes: 50 additions & 0 deletions src/components/ShareButton/ShareButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { useSelector, useDispatch } from "react-redux";
import { useTranslation } from "react-i18next";
import DesignSystemButton from "../DesignSystemButton/DesignSystemButton";
import SaveIcon from "../../assets/icons/save.svg";
import { syncProject, showLoginToSaveModal } from "../../redux/EditorSlice";
import { isOwner } from "../../utils/projectHelpers";

const ShareButton = ({ className, type = "primary" }) => {
const dispatch = useDispatch();
const { t } = useTranslation();

const user = useSelector((state) => state.auth.user);
const project = useSelector((state) => state.editor.project);
const loading = useSelector((state) => state.editor.loading);

const onClickSave = async () => {
// window.plausible("Save button");

if (isOwner(user, project)) {
dispatch(
syncProject("share")({
project,
accessToken: user.access_token,
// autosave: false,
}),
);
} else if (user && project.identifier) {
dispatch(
syncProject("remix")({ project, accessToken: user.access_token }),
);
} else {
dispatch(showLoginToSaveModal());
}
};

return (
loading === "success" && (
<DesignSystemButton
className={className}
onClick={onClickSave}
text={t("header.share")}
textAlways
icon={<SaveIcon />}
type={type}
/>
)
);
};

export default ShareButton;
5 changes: 5 additions & 0 deletions src/redux/EditorSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
createOrUpdateProject,
readProject,
createRemix,
createShare,
deleteProject,
readProjectList,
} from "../utils/apiCallHandler";
Expand All @@ -28,6 +29,10 @@ export const syncProject = (actionName) =>
case "remix":
response = await createRemix(project, accessToken);
break;
case "share":
response = await createShare(project, accessToken);
console.log(response);
break;
case "save":
response = await createOrUpdateProject(project, accessToken);
break;
Expand Down
8 changes: 8 additions & 0 deletions src/utils/apiCallHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ export const createRemix = async (project, accessToken) => {
);
};

export const createShare = async (project, accessToken) => {
return await post(
`${host}/api/projects/${project.identifier}/share`,
{ project },
headers(accessToken),
);
};

export const readProject = async (projectIdentifier, locale, accessToken) => {
const queryString = locale ? `?locale=${locale}` : "";
return await get(
Expand Down
1 change: 1 addition & 0 deletions src/utils/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ i18n
renameProject: "Edit project name",
renameSave: "Save project name",
save: "Save",
share: "Share",
settings: "Settings",
},
imagePanel: {
Expand Down