Skip to content

Commit

Permalink
interview modal
Browse files Browse the repository at this point in the history
  • Loading branch information
GraemeFulton committed Jun 8, 2024
1 parent d264375 commit 112ab16
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 14 deletions.
11 changes: 7 additions & 4 deletions components/Editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const Editor = ({
savePost = false,
updatePost = false,
updatePostSettings = false,
setInitialEditorContent = false,
}) => {
const { user } = useUser({
redirectIfFound: false,
Expand Down Expand Up @@ -155,12 +156,14 @@ const Editor = ({

//check if editor.state.doc.textContent is white space or empty
if (editor.state.doc.textContent.trim() === "") {
editor.commands.clearContent()
setTimeout(()=>{
editor.chain().focus().setTextSelection(0).enter().run()
},100)
editor.commands.clearContent();
setTimeout(() => {
editor.chain().focus().setTextSelection(0).enter().run();
}, 100);
}

if (setInitialEditorContent) setInitialEditorContent(editor);

//add the twitter widget script
addTwitterScript();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const getInterViewTemplate = ({ productName }) => {
type: "italic",
},
],
text: "Welcome to your creator story! This is an interview template that will help share your story and show the human behind the product. The purpose is to showcase work you're excited about, whilst also helping and inspiring readers with their own projects. ",
text: "Welcome to your creator story! This is an interview template that will help share your story and show the human behind the product. The purpose is to showcase work you're excited about, whilst also helping and inspiring readers with their own projects. On completion, your story will be featured on Prototypr and shared with our 25k+ newsletter subscribers and 100k+ Medium followers. ",
},
],
},
Expand Down
136 changes: 136 additions & 0 deletions components/InterviewDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import dynamic from "next/dynamic";
import { Cross2Icon } from "@radix-ui/react-icons";
import {
Dialog,
DialogTrigger,
DialogContentLarge,
DialogTitle,
DialogDescription,
DialogClose,
IconButton,
DialogContent,
} from "@/components/Primitives/Dialog";
import { useState, useEffect } from "react";
import { useRouter } from "next/router";
import Button from "./Primitives/Button";
const Spinner = dynamic(() => import("@/components/atom/Spinner/Spinner"));

const InterviewDialog = ({
tool,
open,
toggleOpen,
createPost,
user,
initialEditor,
relatedPostId,
}) => {
const [loading, setLoading] = useState(false);
const router = useRouter();
return (
<Dialog open={open} onOpenChange={toggleOpen}>
<DialogContentLarge
onPointerDownOutside={e => e.preventDefault()}
className="w-full p-0 overflow-hidden rounded-2xl"
variant=""
>
<div className=" bg-blue-300 relative w-full">
<img src="https://prototypr.io/static/images/earth.png" />
{tool?.attributes?.logo?.data?.attributes?.url ? (
<div className="absolute bg-blue-300/20 top-0 left-0 w-full h-full">
<div className="relative h-full w-full flex flex-col justify-center">
<div className="my-auto mx-auto ">
<img
src={tool?.attributes?.logo?.data?.attributes?.url}
className="w-20 h-20 mx-auto rounded-2xl shadow-lg "
/>
<h2 className="text-white font-medium mt-1 text-xl tracking-tight drop-shadow-md">
{tool.attributes?.title}
</h2>
</div>
</div>
</div>
) : null}
</div>
<div className="bg-white z-10 relative -mt-6 p-4 rounded-t-3xl">
<DialogTitle className="text-2xl tracking-tight">
Get your story featured
</DialogTitle>
<DialogDescription>
<p className="text-gray-500">
We want to share the humans behind the products and the stories
that make them unique. Share your product journey and get
featured.
</p>
</DialogDescription>

<div className="text-base text-gray-800">
<h3 className="font-semibold tracking-tight">How it works:</h3>
<ol className="list-decimal list-inside mb-3 pl-4 mt-2">
<li className="mb-0.5">
Fill in the following 'creator story template' and submit it to
be featured.
</li>
<li className="mb-0.5">
We'll review and get back to you with feedback and questions.
</li>
<li>
Then we'll collaboratively edit to help tell <i>your</i> story.
</li>
</ol>
<p>
Once done, we'll publish it and send it out in the newsletter to{" "}
<span className="text-underline">25k+ subscribers</span>. and{" "}
<span className="text-underline">100k+ followers</span> on the
Prototypr Medium publication.
</p>
<div className="w-full flex justify-start">
<Button
disabled={loading}
className="mt-6 cursor-pointe rounded-full"
onClick={async () => {
setLoading(true);

try {
const postInfo = await createPost({
user,
editor: initialEditor,
forReview: false,
relatedPost: relatedPostId,
});
//set the new slug
localStorage.removeItem("wipInterview");

router.push(
`/toolbox/post/${relatedPostId}/interview/${postInfo?.id}`
);
} catch (e) {
setLoading(false);
alert("Error creating post. Please try again.");
}
}}
>
{loading ? (
<div className="mx-auto ml-0.5 opacity-50">
<Spinner size="sm" />
</div>
) : (
<>Start your story</>
)}
</Button>
</div>
</div>
</div>

<DialogClose className="m-1 pointer-events-auto" asChild>
<IconButton
className="bg-gray-200 shadow border border-gray-800 cursor-pointer"
aria-label="Close"
>
<Cross2Icon />
</IconButton>
</DialogClose>
</DialogContentLarge>
</Dialog>
);
};
export default InterviewDialog;
7 changes: 7 additions & 0 deletions lib/queries/singleToolById.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ export default `
id
}
}
logo{
data{
attributes{
url
}
}
}
link
date
legacyFeaturedImage:legacyMedia{
Expand Down
39 changes: 30 additions & 9 deletions pages/toolbox/post/[id]/interview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dynamic from "next/dynamic";
// import Layout from "@/components/layout-editor";

import useUser from "@/lib/iron-session/useUser";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { addTwitterScript } from "@/components/Editor/editorHooks/libs/addTwitterScript";

import Editor from "@/components/Editor/Editor";
Expand All @@ -14,6 +14,7 @@ import useCreate from "@/components/Editor/editorHooks/newPost/useCreate";
import { useRouter } from "next/router";
import EditorNav from "@/components/EditorNav";
import { getToolById } from "@/lib/api";
import InterviewDialog from "@/components/InterviewDialog";

/**
* Write
Expand All @@ -25,7 +26,7 @@ import { getToolById } from "@/lib/api";
*
* @returns
*/
export default function InterviewEditor({tool}) {
export default function InterviewEditor({ tool }) {
const router = useRouter();
const { user } = useUser({
// redirectTo: '/account',
Expand All @@ -45,7 +46,7 @@ export default function InterviewEditor({tool}) {
const { canEdit, loading, initialContent, postStatus } = useLoad({
user,
interview: true,
productName:tool?.attributes?.title
productName: tool?.attributes?.title,
});

//create new post hook
Expand All @@ -62,6 +63,17 @@ export default function InterviewEditor({tool}) {
localStorage.setItem("wipInterview", JSON.stringify(json));
};

const [dialogOpen, setDialogOpen] = useState(true);
const [initialEditor, setInitialEditor] = useState(null);

const toggleDialog = () => {
setDialogOpen(!dialogOpen);
};

const setInitialEditorContent = editor => {
setInitialEditor(editor);
};

/**
* savePost
* when save button is clicked
Expand Down Expand Up @@ -90,15 +102,14 @@ export default function InterviewEditor({tool}) {
}
};


if(router.isFallback){
if (router.isFallback) {
return (
<div className="my-auto h-screen flex flex-col justify-center text-center">
<div className="mx-auto opacity-50">
<Spinner />
</div>
</div>
)
);
}

return (
Expand All @@ -125,6 +136,7 @@ export default function InterviewEditor({tool}) {
<Editor
canEdit={canEdit}
initialContent={initialContent}
setInitialEditorContent={setInitialEditorContent}
postStatus={postStatus}
//functions
createPost={createPost}
Expand All @@ -137,6 +149,15 @@ export default function InterviewEditor({tool}) {
)}
</div>
</div>
<InterviewDialog
tool={tool}
initialEditor={initialEditor}
createPost={createPost}
toggleOpen={toggleDialog}
open={dialogOpen}
user={user}
relatedPostId={router.query.id}
/>
</>
);
}
Expand All @@ -146,7 +167,7 @@ export async function getStaticProps({ params, preview = null, locale }) {
try {
data = await getToolById(params.id, preview);
} catch (error) {
console.error('Failed to get tool:', error);
console.error("Failed to get tool:", error);
return {
notFound: true,
};
Expand All @@ -163,6 +184,6 @@ export async function getStaticProps({ params, preview = null, locale }) {
export async function getStaticPaths() {
return {
paths: [],
fallback: 'blocking',
fallback: "blocking",
};
}
}

0 comments on commit 112ab16

Please sign in to comment.