-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client: remove need for multiple post page URLs
- Loading branch information
Showing
7 changed files
with
189 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import PasswordModal from "@components/new-post/password-modal" | ||
import { Page, useToasts } from "@geist-ui/core" | ||
import { Post } from "@lib/types" | ||
import { useRouter } from "next/router" | ||
import { useState } from "react" | ||
|
||
type Props = { | ||
setPost: (post: Post) => void | ||
} | ||
|
||
const PasswordModalPage = ({ setPost }: Props) => { | ||
const router = useRouter() | ||
const { setToast } = useToasts() | ||
const [isPasswordModalOpen, setIsPasswordModalOpen] = useState(true) | ||
|
||
const onSubmit = async (password: string) => { | ||
const res = await fetch( | ||
`/server-api/posts/authenticate?id=${router.query.id}&password=${password}`, | ||
{ | ||
method: "GET", | ||
headers: { | ||
"Content-Type": "application/json" | ||
} | ||
} | ||
) | ||
|
||
if (!res.ok) { | ||
setToast({ | ||
type: "error", | ||
text: "Wrong password" | ||
}) | ||
return | ||
} | ||
|
||
const data = await res.json() | ||
if (data) { | ||
if (data.error) { | ||
setToast({ | ||
text: data.error, | ||
type: "error" | ||
}) | ||
} else { | ||
setIsPasswordModalOpen(false) | ||
setPost(data) | ||
} | ||
} | ||
} | ||
|
||
const onClose = () => { | ||
setIsPasswordModalOpen(false) | ||
router.push("/") | ||
} | ||
|
||
return ( | ||
<PasswordModal | ||
creating={false} | ||
onClose={onClose} | ||
onSubmit={onSubmit} | ||
isOpen={isPasswordModalOpen} | ||
/> | ||
) | ||
} | ||
|
||
export default PasswordModalPage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.