├── .env.example ├── .eslintrc.json ├── .gitignore ├── .npmrc ├── .vscode └── settings.json ├── LICENSE ├── README.MD ├── api ├── dev.to │ ├── index.ts │ └── types.ts ├── hashnode │ ├── index.ts │ └── types.ts └── medium │ ├── index.ts │ └── types.ts ├── app ├── (home) │ ├── components │ │ ├── CTA.tsx │ │ ├── Features.tsx │ │ ├── Footer.tsx │ │ ├── Hero.tsx │ │ └── StartPublishing.tsx │ ├── layout.tsx │ └── page.tsx ├── api │ ├── dev.to │ │ ├── publish │ │ │ └── route.ts │ │ └── republish │ │ │ └── route.ts │ ├── get-integrated-blogs │ │ └── route.ts │ └── hashNode │ │ ├── get-tags │ │ └── route.ts │ │ ├── publish │ │ └── route.ts │ │ └── republish │ │ └── route.ts ├── auth │ ├── callback │ │ └── route.ts │ ├── components │ │ └── LayoutWrapper.tsx │ ├── forgot-password │ │ └── page.tsx │ ├── layout.tsx │ ├── loading.tsx │ ├── page.tsx │ ├── reset-password │ │ └── page.tsx │ └── sign-up │ │ └── page.tsx ├── dashboard │ ├── blog │ │ └── [blogId] │ │ │ ├── BlogProvider.tsx │ │ │ ├── components │ │ │ ├── BlogActions.tsx │ │ │ ├── BlogContent.tsx │ │ │ ├── BlogHeader.tsx │ │ │ ├── BlogPrimaryDetails.tsx │ │ │ ├── ImportBlogModal.tsx │ │ │ └── PubRepBlog │ │ │ │ ├── BlogCoverImageUploadAndPreview.tsx │ │ │ │ ├── DevToDetails.tsx │ │ │ │ ├── Drawer.tsx │ │ │ │ ├── HashNodeDetails.tsx │ │ │ │ ├── index.tsx │ │ │ │ └── provider.tsx │ │ │ ├── layout.tsx │ │ │ ├── not-found.tsx │ │ │ └── page.tsx │ ├── components │ │ ├── Blogs.tsx │ │ ├── ConnectedBlogAccounts.tsx │ │ ├── Header.tsx │ │ ├── LayoutWrapper.tsx │ │ ├── Stats.tsx │ │ └── TopSection.tsx │ ├── error.tsx │ ├── layout.tsx │ ├── loading.tsx │ ├── page.tsx │ ├── providers │ │ ├── dashboard.tsx │ │ ├── delete-blog.tsx │ │ └── user.tsx │ └── settings │ │ ├── Integrations.tsx │ │ ├── integration-status │ │ └── route.ts │ │ ├── layout.tsx │ │ └── page.tsx ├── error.tsx ├── favicon.ico ├── globals.css ├── home │ ├── components │ │ ├── CTA.tsx │ │ ├── Features.tsx │ │ ├── Footer.tsx │ │ ├── Hero.tsx │ │ └── StartPublishing.tsx │ ├── layout.tsx │ └── page.tsx ├── layout.tsx ├── loading.tsx └── middleware.ts ├── assets ├── jpg │ ├── app-preview.jpg │ └── default-user-avatar.jpg ├── logos │ ├── dev-to.png │ ├── dev-to.svg │ ├── hashnode.png │ ├── medium.png │ ├── notion.png │ ├── refine.svg │ └── supabase.svg └── svg │ ├── all-in-one-solution-icon.svg │ ├── connect-with-multiple-accounts-icon.svg │ ├── distraction-free-icon.svg │ ├── empty.svg │ ├── get-started.svg │ ├── not-found.svg │ ├── publish-multiple-times-icon.svg │ └── update-once-reflect-twice-icon.svg ├── components ├── Conditional.tsx ├── DropzoneModal.tsx ├── Icon.tsx ├── Loader.tsx ├── Logo.tsx ├── MarkdownEditor.tsx ├── Messages.tsx └── NotFound.tsx ├── config └── index.ts ├── fonts └── index.ts ├── helpers ├── blog.ts └── file.ts ├── hooks ├── file.ts ├── useColorModeValue.ts └── useMediaQuery.ts ├── lib ├── editor.tsx ├── mantine.ts ├── query-client.ts ├── supabase.ts └── utils.ts ├── next-env.d.ts ├── next.config.js ├── package.json ├── pnpm-lock.yaml ├── postcss.config.js ├── prisma └── schema.prisma ├── providers ├── app.tsx ├── mantine.tsx ├── navigation-progress.tsx ├── notification.tsx ├── react-query.tsx ├── refine.tsx ├── supabase.tsx └── toast.tsx ├── public ├── home-hero-bg.svg ├── og-twitter.jpg ├── og.jpg └── robots.txt ├── src ├── components │ └── header │ │ └── index.tsx └── utility │ ├── index.ts │ └── supabaseClient.ts ├── tailwind.config.js ├── tsconfig.json └── types ├── index.ts ├── supabase.d.ts └── supabase.ts /.env.example: -------------------------------------------------------------------------------- 1 | NEXT_PUBLIC_APP_URL=http://localhost:3000 2 | NEXT_PUBLIC_SUPABASE_URL= 3 | NEXT_PUBLIC_SUPABASE_ANON_KEY= 4 | SUPABASE_SERVICE_ROLE_KEY= 5 | DATABASE_URL= 6 | DIRECT_URL= 7 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # npm 2 | node_modules 3 | # next.js build files 4 | .next 5 | # environment variables 6 | .env 7 | .env.* 8 | !.env.example -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | legacy-peer-deps=true 2 | strict-peer-dependencies=false 3 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "cSpell.words": ["supabase"], 3 | "typescript.tsdk": "node_modules\\typescript\\lib" 4 | } 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2023 Minhazur Rahaman Ratul 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | ## PublishWise 2 | 3 | ![null](https://tpwpzkeqppkvywajnezp.supabase.co/storage/v1/object/public/blog-images/3212fce1-4595-446c-a9ab-40c9e148cf8a/59ef2ba0-4e77-4ed7-a18f-9c3938064ce2/06c26644-fd1f-48d7-8500-103db915c8e7.jpg) 4 | 5 | ### Project Demo link 6 | 7 | The project is live at [PublishWise.ink](http://publishwise.ink) 8 | 9 | ## About 10 | 11 | PublishWise is a tool that allows you to write and publish blogs from a single platform. It includes an ideal editor for writing blogs and publishing them on Dev.to and HashNode (with more to come). You can easily make updates to your blog that has been published in both Dev.to and HashNode by modifying it once on PublishWise. It simplifies cross-posting and consolidates your blogs onto a single platform. This project has a lot of potential and will continue to add more valuable features in the future. 12 | 13 | ### Description 14 | 15 | This project was bootstrapped using [Refine](http://refine.dev). It uses [Supabase](http://supabase.com) as the database, storage, and auth provider. The UI is built using the [Mantine](http://mantine.dev) UI library together with Refine. Other than that, it uses Refine data hooks for performing queries and mutations throughout the whole application. The whole application is built on top of the Next.js app directory and utilizes the new features of Next.js. 16 | 17 | ### Participants 18 | 19 | - Minhazur Rahaman Ratul ([@developeratul](http://developeratul.com)) 20 | 21 | 22 | 23 | ### Preview 24 | 25 | The dashboard (dark) 26 | 27 | ![null](https://tpwpzkeqppkvywajnezp.supabase.co/storage/v1/object/public/blog-images/3212fce1-4595-446c-a9ab-40c9e148cf8a/59ef2ba0-4e77-4ed7-a18f-9c3938064ce2/bf335128-f600-4eb3-9147-cef0b3985fc6.jpeg)The dashboard (light) 28 | 29 | ![null](https://tpwpzkeqppkvywajnezp.supabase.co/storage/v1/object/public/blog-images/3212fce1-4595-446c-a9ab-40c9e148cf8a/59ef2ba0-4e77-4ed7-a18f-9c3938064ce2/afc982be-a0e6-47e5-a99f-ad7e79b0b6d4.jpeg)The Editor 30 | 31 | ![null](https://tpwpzkeqppkvywajnezp.supabase.co/storage/v1/object/public/blog-images/3212fce1-4595-446c-a9ab-40c9e148cf8a/59ef2ba0-4e77-4ed7-a18f-9c3938064ce2/c9c6cecb-2372-4a28-9fc1-dfc6c1e1b50f.jpeg)The Editor (light) 32 | 33 | ![null](https://tpwpzkeqppkvywajnezp.supabase.co/storage/v1/object/public/blog-images/3212fce1-4595-446c-a9ab-40c9e148cf8a/59ef2ba0-4e77-4ed7-a18f-9c3938064ce2/cd7b20b9-f8b2-402d-ba53-657319d1de12.jpeg)Settings 34 | 35 | ![null](https://tpwpzkeqppkvywajnezp.supabase.co/storage/v1/object/public/blog-images/3212fce1-4595-446c-a9ab-40c9e148cf8a/59ef2ba0-4e77-4ed7-a18f-9c3938064ce2/95d68fec-4af2-47fd-9f33-cc94fe5bf43f.jpeg)Settings (light) 36 | 37 | ![null](https://tpwpzkeqppkvywajnezp.supabase.co/storage/v1/object/public/blog-images/3212fce1-4595-446c-a9ab-40c9e148cf8a/59ef2ba0-4e77-4ed7-a18f-9c3938064ce2/a2ee7ec5-8fd3-4db2-81ec-c893e6758c02.jpeg)Landing page (light) 38 | 39 | ![null](https://tpwpzkeqppkvywajnezp.supabase.co/storage/v1/object/public/blog-images/3212fce1-4595-446c-a9ab-40c9e148cf8a/59ef2ba0-4e77-4ed7-a18f-9c3938064ce2/713cceb4-419e-40ed-a1f6-08b39ba110dd.jpeg) 40 | 41 | ### Prerequisites 42 | 43 | ``` 44 | Node >= 16 45 | Yarn >= 1.22.19 46 | Npm >= 8.11.0 47 | ``` 48 | 49 | ### Install Project 50 | 51 | - Clone the repository: 52 | 53 | 54 | 55 | ``` 56 | git clone git@github.com:developeratul/publish-wise-refine.git 57 | ``` 58 | 59 | - Change directory and install dependencies: 60 | 61 | 62 | 63 | ``` 64 | cd publish-wise-refine 65 | yarn 66 | ``` 67 | 68 | - Create `.env` file and fill up the credentials 69 | 70 | 71 | 72 | ``` 73 | cp .env.example .env 74 | ``` 75 | 76 | - Sync prisma schema with the database: 77 | 78 | ```bash 79 | yarn push-db 80 | ``` 81 | 82 | - If you have followed everything mentioned above properly, you should be able to run: 83 | 84 | 85 | 86 | ``` 87 | yarn dev 88 | ``` 89 | 90 | 🚀 91 | -------------------------------------------------------------------------------- /api/dev.to/index.ts: -------------------------------------------------------------------------------- 1 | import { BlogUser, PublishBlogResponse } from "@/types"; 2 | import Axios, { AxiosInstance } from "axios"; 3 | import { DevToArticleInput, DevToRepublishArticle, DevToUser } from "./types"; 4 | 5 | export class DevToApiClient { 6 | private _apiKey: string; 7 | public axios: AxiosInstance; 8 | 9 | constructor(_apiKey: string) { 10 | this._apiKey = _apiKey; 11 | this.axios = Axios.create({ 12 | baseURL: "https://dev.to/api", 13 | headers: { 14 | "api-key": this._apiKey, 15 | accept: "application/vnd.forem.api-v1+json", 16 | }, 17 | }); 18 | } 19 | 20 | public async publish(article: DevToArticleInput): Promise { 21 | interface Response { 22 | id: number; 23 | url: string; 24 | } 25 | const { data } = await this.axios.post("/articles", { 26 | article, 27 | }); 28 | return { url: data.url, id: data.id.toString() }; 29 | } 30 | 31 | public async republish(id: string, article: DevToRepublishArticle): Promise { 32 | const { data } = await this.axios.put(`/articles/${id}`, { 33 | article, 34 | }); 35 | // Change this 36 | return { url: data.url, id: data.id.toString() }; 37 | } 38 | 39 | public async getAuthUser(): Promise { 40 | const { id, name, profile_image, username } = (await this.axios.get("/users/me")) 41 | .data; 42 | return { id: id.toString(), username, name, avatarUrl: profile_image }; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /api/dev.to/types.ts: -------------------------------------------------------------------------------- 1 | export interface DevToArticleInput { 2 | title: string; 3 | description?: string; 4 | body_markdown: string; 5 | published?: boolean; 6 | series?: string; 7 | main_image: string | null; 8 | canonical_url?: string; 9 | tags?: string[]; 10 | } 11 | 12 | export interface DevToPublishArticleResponse { 13 | id: number; 14 | url: string; 15 | } 16 | 17 | export interface DevToUser { 18 | id: number; 19 | username: string; 20 | name: string; 21 | profile_image: string; 22 | } 23 | 24 | export type DevToRepublishArticle = Omit; 25 | -------------------------------------------------------------------------------- /api/hashnode/index.ts: -------------------------------------------------------------------------------- 1 | import { BlogUser, PublishBlogResponse } from "@/types"; 2 | import Axios, { AxiosInstance } from "axios"; 3 | import { 4 | HashNodeArticleInput, 5 | HashNodeTag, 6 | HashnodeUser, 7 | RepublishHashNodeArticleInput, 8 | } from "./types"; 9 | 10 | export class HashNodeApiClient { 11 | private _apiKey: string; 12 | public axios: AxiosInstance; 13 | 14 | constructor(_apiKey: string) { 15 | this._apiKey = _apiKey; 16 | this.axios = Axios.create({ 17 | baseURL: "http://api.hashnode.com", 18 | headers: { 19 | Authorization: this._apiKey, 20 | accept: "application/json", 21 | }, 22 | }); 23 | } 24 | 25 | public async publish( 26 | username: string, 27 | input: HashNodeArticleInput 28 | ): Promise { 29 | // type Response = { 30 | // data: { 31 | // createStory: { 32 | // message: string; 33 | // post: { 34 | // slug: string; 35 | // author: { 36 | // username: string; 37 | // }; 38 | // publication: { 39 | // domain: string; 40 | // }; 41 | // }; 42 | // }; 43 | // }; 44 | // }; 45 | 46 | const { publication } = await this.getAuthUser(username); 47 | 48 | if (!publication) throw new Error("You don't have any blog created on HashNode"); 49 | 50 | const { data } = await this.axios.post("/", { 51 | query: ` 52 | mutation PublishBlog($input: CreateStoryInput!) { 53 | createStory(input: $input) { 54 | post { 55 | _id 56 | slug 57 | author { 58 | username 59 | } 60 | publication { 61 | domain 62 | } 63 | } 64 | } 65 | } 66 | `, 67 | variables: { input: { ...input, isPartOfPublication: { publicationId: publication._id } } }, 68 | }); 69 | 70 | if (data.errors?.length) { 71 | throw new Error(data.errors[0].message); 72 | } 73 | 74 | const { 75 | data: { 76 | createStory: { post }, 77 | }, 78 | } = data; 79 | 80 | const articleUrl = await this.getArticleUrl(post.author.username, post.slug); 81 | 82 | return { url: articleUrl, id: post._id }; 83 | } 84 | 85 | public async republish(postId: string, username: string, input: RepublishHashNodeArticleInput) { 86 | const { publication } = await this.getAuthUser(username); 87 | 88 | if (!publication) throw new Error("You don't have any blog created on HashNode"); 89 | 90 | const { data } = await this.axios.post("/", { 91 | query: ` 92 | mutation UpdateStory($postId: String!, $input: UpdateStoryInput!) { 93 | updateStory(postId: $postId, input: $input) { 94 | post { 95 | _id 96 | slug 97 | author { 98 | username 99 | } 100 | publication { 101 | domain 102 | } 103 | } 104 | } 105 | } 106 | `, 107 | variables: { 108 | postId, 109 | input: { ...input, isPartOfPublication: { publicationId: publication._id } }, 110 | }, 111 | }); 112 | 113 | if (data.errors?.length) { 114 | throw new Error(data.errors[0].message); 115 | } 116 | 117 | const { 118 | data: { 119 | updateStory: { post }, 120 | }, 121 | } = data; 122 | 123 | const articleUrl = await this.getArticleUrl(post.author.username, post.slug); 124 | 125 | return { url: articleUrl, id: post._id }; 126 | } 127 | 128 | public async getArticleUrl(username: string, slug: string) { 129 | const { 130 | publication: { domain }, 131 | } = await this.getAuthUser(username); 132 | let blogDomain = domain ? domain : `${username}.hashnode.dev`; 133 | return `http://${blogDomain}/${slug}`; 134 | } 135 | 136 | public async getAvailableTags(): Promise<{ tags: HashNodeTag[] }> { 137 | const { 138 | data: { 139 | data: { tagCategories }, 140 | }, 141 | } = await this.axios.post<{ data: { tagCategories: HashNodeTag[] } }>("/", { 142 | query: ` 143 | query Tags { 144 | tagCategories { 145 | _id 146 | name 147 | slug 148 | } 149 | } 150 | `, 151 | }); 152 | 153 | return { tags: tagCategories }; 154 | } 155 | 156 | public async getAuthUser(hashNodeUsername: string): Promise< 157 | BlogUser & { 158 | publication: { _id: string; domain: string | null }; 159 | } 160 | > { 161 | const { 162 | data: { 163 | data: { 164 | user: { _id, name, username, photo, publication }, 165 | }, 166 | }, 167 | } = await this.axios.post<{ data: { user: HashnodeUser } }>("/", { 168 | query: ` 169 | query($username: String!) { 170 | user(username: $username) { 171 | _id 172 | username 173 | name 174 | photo 175 | publication { 176 | _id 177 | domain 178 | } 179 | } 180 | } 181 | `, 182 | variables: { username: hashNodeUsername }, 183 | }); 184 | return { 185 | id: _id, 186 | name, 187 | username, 188 | avatarUrl: photo, 189 | publication, 190 | }; 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /api/hashnode/types.ts: -------------------------------------------------------------------------------- 1 | export interface HashNodeTag { 2 | _id: string; 3 | slug: string; 4 | name: string; 5 | } 6 | 7 | export interface HashnodeUser { 8 | _id: string; 9 | username: string; 10 | name: string; 11 | photo: string; 12 | publication: { 13 | _id: string; 14 | domain: string | null; 15 | }; 16 | } 17 | 18 | export interface HashNodeArticleInput { 19 | title: string; 20 | contentMarkdown: string; 21 | coverImageURL: string | null; 22 | subtitle?: string; 23 | slug: string; 24 | tags: Omit[]; 25 | isRepublished?: { originalArticleURL: string }; 26 | } 27 | 28 | export type RepublishHashNodeArticleInput = Omit; 29 | -------------------------------------------------------------------------------- /api/medium/index.ts: -------------------------------------------------------------------------------- 1 | import { BlogUser, PublishBlogResponse } from "@/types"; 2 | import Axios, { AxiosInstance } from "axios"; 3 | import { MediumUser } from "./types"; 4 | 5 | export class MediumApiClient { 6 | private _apiKey: string; 7 | public axios: AxiosInstance; 8 | 9 | constructor(_apiKey: string) { 10 | this._apiKey = _apiKey; 11 | this.axios = Axios.create({ 12 | baseURL: "http://api.medium.com/v1", 13 | headers: { 14 | Authorization: `Bearer ${this._apiKey}`, 15 | accept: "application/json", 16 | }, 17 | }); 18 | } 19 | 20 | public async publish(): Promise { 21 | return { url: "", id: "" }; 22 | } 23 | 24 | public async getAuthUser(): Promise { 25 | const { 26 | data: { id, name, username, imageUrl }, 27 | } = await this.axios.get("/me"); 28 | return { id, name, username, avatarUrl: imageUrl }; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /api/medium/types.ts: -------------------------------------------------------------------------------- 1 | export interface MediumUser { 2 | id: string; 3 | username: string; 4 | name: string; 5 | url: string; 6 | imageUrl: string; 7 | } 8 | -------------------------------------------------------------------------------- /app/(home)/components/CTA.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import Icon from "@/components/Icon"; 3 | import useMediaQuery from "@/hooks/useMediaQuery"; 4 | import { cn } from "@/lib/utils"; 5 | import { Button } from "@mantine/core"; 6 | import Link from "next/link"; 7 | 8 | export default function CTA(props: { className?: string }) { 9 | const { className } = props; 10 | const { isOverXs } = useMediaQuery(); 11 | return ( 12 | 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /app/(home)/components/Features.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import NotionLogoSrc from "@/assets/logos/notion.png"; 3 | import AllInOneSolutionIcon from "@/assets/svg/all-in-one-solution-icon.svg"; 4 | import ConnectWithMultipleIcon from "@/assets/svg/connect-with-multiple-accounts-icon.svg"; 5 | import DistractionFreeIconSrc from "@/assets/svg/distraction-free-icon.svg"; 6 | import WriteOncePublishTwiceIconSrc from "@/assets/svg/publish-multiple-times-icon.svg"; 7 | import UpdateOnceReflectTwiceIcon from "@/assets/svg/update-once-reflect-twice-icon.svg"; 8 | import useColorModeValue from "@/hooks/useColorModeValue"; 9 | import useMediaQuery from "@/hooks/useMediaQuery"; 10 | import { AppProps } from "@/types"; 11 | import { Box, Center, Container, SimpleGrid, Stack, Title, useMantineTheme } from "@mantine/core"; 12 | import Image from "next/image"; 13 | import CTA from "./CTA"; 14 | 15 | const IMAGE_WIDTH = 60; 16 | 17 | function IconWrapper(props: AppProps) { 18 | const { children } = props; 19 | const theme = useMantineTheme(); 20 | const primaryShade = useColorModeValue("6", "8"); 21 | return ( 22 | 27 | {children} 28 | 29 | ); 30 | } 31 | 32 | function SingleFeature(props: { label: string; icon: React.ReactNode; maw?: number }) { 33 | const { label, icon, maw } = props; 34 | return ( 35 | 36 | {icon} 37 | 45 | <div className="text-white!">{label}</div> 46 | 47 | 48 | ); 49 | } 50 | 51 | export default function Features() { 52 | const { isOverXs, isOverMd } = useMediaQuery(); 53 | return ( 54 | 55 |
56 | 57 | 58 | 63 | Notion logo 64 | 65 | } 66 | /> 67 | 72 | Distraction free 73 | 74 | } 75 | /> 76 | 80 | Write once publish multiple times 85 | 86 | } 87 | /> 88 | 92 | Write once publish multiple times 97 | 98 | } 99 | /> 100 | 104 | Connect with multiple blog accounts 109 | 110 | } 111 | /> 112 | 117 | All in one solution 118 | 119 | } 120 | /> 121 | 122 | 123 | 124 |
125 |
126 | ); 127 | } 128 | -------------------------------------------------------------------------------- /app/(home)/components/Footer.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import RefineLogoSrc from "@/assets/logos/refine.svg"; 3 | import SupabaseLogoSrc from "@/assets/logos/supabase.svg"; 4 | import Icon from "@/components/Icon"; 5 | import Logo from "@/components/Logo"; 6 | import { Anchor, Flex, Stack, Text, useMantineTheme } from "@mantine/core"; 7 | import Image from "next/image"; 8 | 9 | export default function Footer() { 10 | const theme = useMantineTheme(); 11 | return ( 12 |
16 | 17 | 18 | 19 | 20 | Refine logo 21 | 22 | 23 | 24 | Supabase logo 25 | 26 | 27 | 28 | Designed and Developed by{" "} 29 | 30 | @developeratul 31 | 32 | 33 | 34 |
35 | ); 36 | } 37 | -------------------------------------------------------------------------------- /app/(home)/components/Hero.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import AppPreviewSrc from "@/assets/jpg/app-preview.jpg"; 4 | import Logo from "@/components/Logo"; 5 | import useMediaQuery from "@/hooks/useMediaQuery"; 6 | import { BackgroundImage, Card, Center, Container, Stack, Title } from "@mantine/core"; 7 | import Image from "next/image"; 8 | import CTA from "./CTA"; 9 | 10 | export default function Hero() { 11 | const { isOverXs } = useMediaQuery(); 12 | return ( 13 | 14 | 15 |
16 | 17 | 18 | 19 | 23 | The one place to write and publish your blogs 24 | 25 | 26 | 27 | 28 | PublishWise editor preview 33 | 34 | 35 |
36 |
37 |
38 | ); 39 | } 40 | -------------------------------------------------------------------------------- /app/(home)/components/StartPublishing.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import GetStartedSrc from "@/assets/svg/get-started.svg"; 3 | import Icon from "@/components/Icon"; 4 | import { Badge, Center, Container, Divider, List, Stack, ThemeIcon, Title } from "@mantine/core"; 5 | import Image from "next/image"; 6 | import React from "react"; 7 | import CTA from "./CTA"; 8 | 9 | export default function StartPublishing() { 10 | return ( 11 | 12 | 13 | 14 |
15 | 16 | Get started with PublishWise 17 | 18 | 19 | Ready to start publishing? 20 | 21 | 25 | 26 | 27 | } 28 | > 29 | Write, publish and edit your blogs from one place 30 | Cross-posting made simple 31 | Don't ever be repetitive while publishing 32 | Publish blogs on Dev.to and HashNode. More coming soon 33 | 34 | Schedule blogs Coming soon... 35 | 36 | 37 | 38 | 39 | 40 |
41 |
42 |
43 | ); 44 | } 45 | -------------------------------------------------------------------------------- /app/(home)/layout.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import Logo from "@/components/Logo"; 3 | import useMediaQuery from "@/hooks/useMediaQuery"; 4 | import { AppProps } from "@/types"; 5 | import { AppShell, Group, Header } from "@mantine/core"; 6 | import CTA from "./components/CTA"; 7 | 8 | export default function HomeLayout(props: AppProps) { 9 | const { children } = props; 10 | const { isOverSm, isOverXs } = useMediaQuery(); 11 | return ( 12 | 15 | 16 | 17 | 18 | 19 | 20 | } 21 | styles={(theme) => ({ 22 | main: { 23 | backgroundColor: 24 | theme.colorScheme === "dark" ? theme.colors.dark[7] : theme.colors.gray[1], 25 | padding: 0, 26 | }, 27 | })} 28 | > 29 | {children} 30 | 31 | ); 32 | } 33 | -------------------------------------------------------------------------------- /app/(home)/page.tsx: -------------------------------------------------------------------------------- 1 | import { createServerComponentClient } from "@supabase/auth-helpers-nextjs"; 2 | import nextDynamic from "next/dynamic"; 3 | import { cookies } from "next/headers"; 4 | import { redirect } from "next/navigation"; 5 | const Features = nextDynamic(() => import("./components/Features")); 6 | const Footer = nextDynamic(() => import("./components/Footer")); 7 | const Hero = nextDynamic(() => import("./components/Hero")); 8 | const StartPublishing = nextDynamic(() => import("./components/StartPublishing")); 9 | 10 | export default async function LandingHome() { 11 | const supabase = createServerComponentClient({ cookies }); 12 | const { data } = await supabase.auth.getSession(); 13 | const { session } = data; 14 | 15 | if (session) { 16 | return redirect("/dashboard"); 17 | } 18 | 19 | return ( 20 |
21 | 22 | 23 | 24 |
25 |
26 | ); 27 | } 28 | 29 | export const dynamic = "force-dynamic"; 30 | -------------------------------------------------------------------------------- /app/api/dev.to/publish/route.ts: -------------------------------------------------------------------------------- 1 | import { DevToApiClient } from "@/api/dev.to"; 2 | import { DevToArticleInput } from "@/api/dev.to/types"; 3 | import { AxiosError } from "axios"; 4 | import { NextResponse } from "next/server"; 5 | 6 | export async function POST(req: Request) { 7 | try { 8 | const { apiKey, ...articleInputs }: DevToArticleInput & { apiKey: string } = await req.json(); 9 | 10 | const client = new DevToApiClient(apiKey); 11 | 12 | const { id, url } = await client.publish({ 13 | ...articleInputs, 14 | published: true, 15 | }); 16 | 17 | return NextResponse.json({ id, url }); 18 | } catch (err) { 19 | if (err instanceof AxiosError) { 20 | if (err.response?.status === 401) { 21 | return NextResponse.json( 22 | { message: "Your Dev.to account is not connected with PublishWise" }, 23 | { status: 401 } 24 | ); 25 | } 26 | return NextResponse.json( 27 | { message: err.response?.data.error }, 28 | { status: err.response?.status || 500 } 29 | ); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/api/dev.to/republish/route.ts: -------------------------------------------------------------------------------- 1 | import { DevToApiClient } from "@/api/dev.to"; 2 | import { DevToRepublishArticle } from "@/api/dev.to/types"; 3 | import { AxiosError } from "axios"; 4 | import { NextResponse } from "next/server"; 5 | 6 | export async function POST(req: Request) { 7 | try { 8 | const { 9 | apiKey, 10 | publishedBlogId, 11 | ...articleInput 12 | }: DevToRepublishArticle & { apiKey: string; publishedBlogId: string } = await req.json(); 13 | 14 | const client = new DevToApiClient(apiKey); 15 | 16 | const { id, url } = await client.republish(publishedBlogId, { 17 | ...articleInput, 18 | published: true, 19 | }); 20 | 21 | return NextResponse.json({ id, url }); 22 | } catch (err) { 23 | if (err instanceof AxiosError) { 24 | if (err.response?.status === 401) { 25 | return NextResponse.json( 26 | { message: "Your Dev.to account is not connected with PublishWise" }, 27 | { status: 401 } 28 | ); 29 | } 30 | return NextResponse.json( 31 | { message: err.response?.data.error }, 32 | { status: err.response?.status || 500 } 33 | ); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/api/get-integrated-blogs/route.ts: -------------------------------------------------------------------------------- 1 | import { DevToApiClient } from "@/api/dev.to"; 2 | import { HashNodeApiClient } from "@/api/hashnode"; 3 | import { MediumApiClient } from "@/api/medium"; 4 | import { BlogProviders, BlogUser } from "@/types"; 5 | import { Database } from "@/types/supabase"; 6 | import { createRouteHandlerClient } from "@supabase/auth-helpers-nextjs"; 7 | import { AxiosError } from "axios"; 8 | import { cookies } from "next/headers"; 9 | import { NextResponse } from "next/server"; 10 | 11 | export async function POST(req: Request) { 12 | try { 13 | const { devToAPIKey, hashNodeAPIKey, hashNodeUsername, mediumAPIKey } = ({} = await req.json()); 14 | const supabase = createRouteHandlerClient({ cookies }); 15 | 16 | const { 17 | data: { user }, 18 | } = await supabase.auth.getUser(); 19 | 20 | if (!user) { 21 | return NextResponse.json({ message: "User not authenticated" }, { status: 401 }); 22 | } 23 | 24 | const { error } = await supabase.from("profiles").select("*").eq("userId", user.id).single(); 25 | 26 | if (error) { 27 | return NextResponse.json({ message: error.message }, { status: 500 }); 28 | } 29 | 30 | let devToAccount; 31 | if (devToAPIKey) { 32 | try { 33 | const devToClient = new DevToApiClient(devToAPIKey); 34 | devToAccount = await devToClient.getAuthUser(); 35 | } catch (err) { 36 | devToAccount = undefined; 37 | } 38 | } 39 | 40 | let hashNodeAccount; 41 | if (hashNodeAPIKey && hashNodeUsername) { 42 | try { 43 | const hashNodeClient = new HashNodeApiClient(hashNodeAPIKey); 44 | hashNodeAccount = await hashNodeClient.getAuthUser(hashNodeUsername); 45 | } catch (err) { 46 | hashNodeAccount = undefined; 47 | } 48 | } 49 | 50 | let mediumAccount; 51 | if (mediumAPIKey) { 52 | try { 53 | const mediumClient = new MediumApiClient(mediumAPIKey); 54 | mediumAccount = await mediumClient.getAuthUser(); 55 | } catch (err) { 56 | mediumAccount = null; 57 | } 58 | } 59 | 60 | return NextResponse.json({ 61 | accounts: { 62 | "dev.to": devToAccount, 63 | hashNode: hashNodeAccount, 64 | medium: mediumAccount, 65 | }, 66 | apiKeys: { 67 | "dev.to": devToAPIKey, 68 | hashNode: hashNodeAPIKey, 69 | medium: mediumAPIKey, 70 | }, 71 | }); 72 | } catch (err) { 73 | if (err instanceof AxiosError) { 74 | return NextResponse.json({ message: err.message }, { status: err.response?.status || 500 }); 75 | } 76 | } 77 | } 78 | 79 | export interface GetIntegrationStatusResponse { 80 | accounts: Record; 81 | apiKeys: Record; 82 | } 83 | -------------------------------------------------------------------------------- /app/api/hashNode/get-tags/route.ts: -------------------------------------------------------------------------------- 1 | import { HashNodeApiClient } from "@/api/hashnode"; 2 | import { NextResponse } from "next/server"; 3 | 4 | export async function POST(req: Request) { 5 | const { apiKey } = await req.json(); 6 | 7 | const client = new HashNodeApiClient(apiKey); 8 | 9 | const { tags } = await client.getAvailableTags(); 10 | 11 | return NextResponse.json({ tags }); 12 | } 13 | -------------------------------------------------------------------------------- /app/api/hashNode/publish/route.ts: -------------------------------------------------------------------------------- 1 | import { HashNodeApiClient } from "@/api/hashnode"; 2 | import { HashNodeArticleInput } from "@/api/hashnode/types"; 3 | import { AxiosError } from "axios"; 4 | import { NextResponse } from "next/server"; 5 | 6 | export async function POST(req: Request) { 7 | try { 8 | const { 9 | apiKey, 10 | username, 11 | ...articleInput 12 | }: HashNodeArticleInput & { apiKey: string; username: string } = await req.json(); 13 | 14 | const client = new HashNodeApiClient(apiKey); 15 | 16 | const { id, url } = await client.publish(username, { 17 | ...articleInput, 18 | }); 19 | 20 | return NextResponse.json({ id, url }); 21 | } catch (err) { 22 | if (err instanceof AxiosError) { 23 | if (err.response?.status === 401) { 24 | return NextResponse.json( 25 | { message: "Your HashNode account is not connected with PublishWise" }, 26 | { status: 401 } 27 | ); 28 | } 29 | return NextResponse.json( 30 | { message: err.response?.data?.errors[0]?.message || err.message }, 31 | { status: err.response?.status || 500 } 32 | ); 33 | } else if (err instanceof Error) { 34 | return NextResponse.json({ message: err.message }, { status: 500 }); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/api/hashNode/republish/route.ts: -------------------------------------------------------------------------------- 1 | import { HashNodeApiClient } from "@/api/hashnode"; 2 | import { RepublishHashNodeArticleInput } from "@/api/hashnode/types"; 3 | import { AxiosError } from "axios"; 4 | import { NextResponse } from "next/server"; 5 | 6 | export async function POST(req: Request) { 7 | try { 8 | const { 9 | apiKey, 10 | username, 11 | publishedBlogId, 12 | ...articleInput 13 | }: RepublishHashNodeArticleInput & { 14 | apiKey: string; 15 | username: string; 16 | publishedBlogId: string; 17 | } = await req.json(); 18 | 19 | const client = new HashNodeApiClient(apiKey); 20 | 21 | const { id, url } = await client.republish(publishedBlogId, username, { 22 | ...articleInput, 23 | }); 24 | 25 | return NextResponse.json({ id, url }); 26 | } catch (err) { 27 | if (err instanceof AxiosError) { 28 | if (err.response?.status === 401) { 29 | return NextResponse.json( 30 | { message: "Your HashNode account is not connected with PublishWise" }, 31 | { status: 401 } 32 | ); 33 | } 34 | return NextResponse.json( 35 | { message: err.response?.data?.errors[0]?.message || err.message }, 36 | { status: err.response?.status || 500 } 37 | ); 38 | } else if (err instanceof Error) { 39 | return NextResponse.json({ message: err.message }, { status: 500 }); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/auth/callback/route.ts: -------------------------------------------------------------------------------- 1 | import { absoluteUrl } from "@/lib/utils"; 2 | import { createRouteHandlerClient } from "@supabase/auth-helpers-nextjs"; 3 | import { cookies } from "next/headers"; 4 | import { NextResponse } from "next/server"; 5 | 6 | export async function GET(request: Request) { 7 | const requestUrl = new URL(request.url); 8 | const code = requestUrl.searchParams.get("code"); 9 | 10 | if (code) { 11 | const supabase = createRouteHandlerClient({ cookies }); 12 | await supabase.auth.exchangeCodeForSession(code); 13 | } 14 | 15 | const next = requestUrl.searchParams.get("next"); 16 | 17 | if (next) { 18 | return NextResponse.redirect(absoluteUrl(next)); 19 | } 20 | 21 | // URL to redirect to after sign in process completes 22 | return NextResponse.redirect(requestUrl.origin); 23 | } 24 | -------------------------------------------------------------------------------- /app/auth/components/LayoutWrapper.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import Logo from "@/components/Logo"; 3 | import { AppProps } from "@/types"; 4 | import { AppShell, Card, Stack } from "@mantine/core"; 5 | 6 | export default function AuthLayoutWrapper(props: AppProps) { 7 | const { children } = props; 8 | return ( 9 | ({ 11 | main: { 12 | backgroundColor: 13 | theme.colorScheme === "dark" ? theme.colors.dark[7] : theme.colors.gray[1], 14 | }, 15 | })} 16 | > 17 | 18 | 19 | 20 | {children} 21 | 22 | 23 | 24 | ); 25 | } 26 | -------------------------------------------------------------------------------- /app/auth/forgot-password/page.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import { supabaseClient } from "@/lib/supabase"; 3 | import { absoluteUrl } from "@/lib/utils"; 4 | import { Button, LoadingOverlay, Stack, TextInput, Title } from "@mantine/core"; 5 | import { isEmail, useForm } from "@mantine/form"; 6 | import { AuthError } from "@supabase/supabase-js"; 7 | import { useMutation } from "@tanstack/react-query"; 8 | import { toast } from "react-hot-toast"; 9 | 10 | const initialValues = { email: "" }; 11 | 12 | export default function ForgotPasswordPage() { 13 | const { getInputProps, onSubmit, reset } = useForm({ 14 | initialValues, 15 | validate: { 16 | email: isEmail("Invalid Email"), 17 | }, 18 | }); 19 | const { mutateAsync, isLoading } = useMutation({ 20 | mutationFn: async (values: typeof initialValues) => { 21 | const { email } = values; 22 | const { data, error } = await supabaseClient.auth.resetPasswordForEmail(email, { 23 | redirectTo: absoluteUrl("/auth/callback?next=/auth/reset-password"), 24 | }); 25 | if (error) throw error; 26 | return data; 27 | }, 28 | }); 29 | 30 | const handleSubmit = async (values: typeof initialValues) => { 31 | try { 32 | await mutateAsync(values); 33 | reset(); 34 | toast.success("We have sent email instructions to your email"); 35 | } catch (err) { 36 | if (err instanceof AuthError) { 37 | toast.error(err.message); 38 | } 39 | } 40 | }; 41 | 42 | return ( 43 | 44 | 45 | Forgot password 46 | 47 |
48 | 49 | 50 | 51 | 52 |
53 | ); 54 | } 55 | -------------------------------------------------------------------------------- /app/auth/layout.tsx: -------------------------------------------------------------------------------- 1 | import { AppProps } from "@/types"; 2 | import AuthLayoutWrapper from "./components/LayoutWrapper"; 3 | 4 | export default async function AuthLayout(props: AppProps) { 5 | const { children } = props; 6 | return {children}; 7 | } 8 | -------------------------------------------------------------------------------- /app/auth/loading.tsx: -------------------------------------------------------------------------------- 1 | import { FullPageRelativeLoader } from "@/components/Loader"; 2 | 3 | export default function DashboardLoading() { 4 | return ; 5 | } 6 | -------------------------------------------------------------------------------- /app/auth/page.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import { supabaseClient } from "@/lib/supabase"; 3 | import { 4 | Anchor, 5 | Button, 6 | LoadingOverlay, 7 | PasswordInput, 8 | Stack, 9 | Text, 10 | TextInput, 11 | Title, 12 | } from "@mantine/core"; 13 | import { hasLength, isEmail, useForm } from "@mantine/form"; 14 | import { AuthError } from "@supabase/supabase-js"; 15 | import { useMutation } from "@tanstack/react-query"; 16 | import Link from "next/link"; 17 | import { toast } from "react-hot-toast"; 18 | 19 | const initialValues = { email: "", password: "" }; 20 | 21 | export default function LoginPage() { 22 | const { onSubmit, getInputProps } = useForm({ 23 | initialValues, 24 | validate: { 25 | email: isEmail("Invalid Email"), 26 | password: hasLength({ min: 6 }, "Password must contain at least 6 chars"), 27 | }, 28 | }); 29 | const { mutateAsync, isLoading } = useMutation({ 30 | mutationFn: async (values: typeof initialValues) => { 31 | const { email, password } = values; 32 | const { data, error } = await supabaseClient.auth.signInWithPassword({ 33 | email, 34 | password, 35 | }); 36 | if (error) throw error; 37 | return data; 38 | }, 39 | }); 40 | 41 | const handleSubmit = async (values: typeof initialValues) => { 42 | try { 43 | const { user } = await mutateAsync(values); 44 | toast.success(`Welcome back, ${user.user_metadata.first_name}!`); 45 | window.location.href = "/dashboard"; 46 | } catch (err) { 47 | if (err instanceof AuthError) { 48 | toast.error(err.message); 49 | } 50 | } 51 | }; 52 | 53 | return ( 54 | 55 | 56 | Sign in 57 | 58 |
59 | 60 | 61 | 62 | 63 | 64 | 65 | Don't have an account?{" "} 66 | 67 | Sign up 68 | 69 | 70 | 71 | 72 | Forgot password 73 | 74 | 75 | 76 | 77 |
78 | ); 79 | } 80 | -------------------------------------------------------------------------------- /app/auth/reset-password/page.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import { supabaseClient } from "@/lib/supabase"; 3 | import { Button, LoadingOverlay, PasswordInput, Stack, Title } from "@mantine/core"; 4 | import { hasLength, matchesField, useForm } from "@mantine/form"; 5 | import { AuthError } from "@supabase/supabase-js"; 6 | import { useMutation } from "@tanstack/react-query"; 7 | import { useRouter } from "next/navigation"; 8 | import { toast } from "react-hot-toast"; 9 | 10 | const initialValues = { password: "", confirmPassword: "" }; 11 | 12 | export default function ResetPasswordPage() { 13 | const { getInputProps, onSubmit, reset } = useForm({ 14 | initialValues, 15 | validate: { 16 | password: hasLength({ min: 6 }, "Password must contain at least 6 chars"), 17 | confirmPassword: matchesField("password", "Passwords must match"), 18 | }, 19 | }); 20 | const { mutateAsync, isLoading } = useMutation({ 21 | mutationFn: async (values: typeof initialValues) => { 22 | const { password } = values; 23 | const { data, error } = await supabaseClient.auth.updateUser({ password }); 24 | if (error) throw error; 25 | return data; 26 | }, 27 | }); 28 | const router = useRouter(); 29 | 30 | const handleSubmit = async (values: typeof initialValues) => { 31 | try { 32 | await mutateAsync(values); 33 | reset(); 34 | router.push("/dashboard"); 35 | toast.success("Your password has successfully been updated"); 36 | } catch (err) { 37 | if (err instanceof AuthError) { 38 | toast.error(err.message); 39 | } 40 | } 41 | }; 42 | 43 | return ( 44 | 45 | 46 | Reset password 47 | 48 |
49 | 50 | 51 | 52 | 53 | 54 |
55 | ); 56 | } 57 | -------------------------------------------------------------------------------- /app/auth/sign-up/page.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import { supabaseClient } from "@/lib/supabase"; 3 | import { absoluteUrl } from "@/lib/utils"; 4 | import { UserMetadata } from "@/types"; 5 | import { 6 | Anchor, 7 | Button, 8 | Group, 9 | LoadingOverlay, 10 | PasswordInput, 11 | Stack, 12 | Text, 13 | TextInput, 14 | Title, 15 | } from "@mantine/core"; 16 | import { hasLength, isEmail, isNotEmpty, useForm } from "@mantine/form"; 17 | import { AuthError } from "@supabase/supabase-js"; 18 | import { useMutation } from "@tanstack/react-query"; 19 | import Link from "next/link"; 20 | import { toast } from "react-hot-toast"; 21 | 22 | const initialValues = { first_name: "", last_name: "", email: "", password: "" }; 23 | 24 | export default function SignUpPage() { 25 | const { getInputProps, onSubmit, reset } = useForm({ 26 | initialValues, 27 | validate: { 28 | first_name: isNotEmpty("First name is required"), 29 | last_name: isNotEmpty("Last name is required"), 30 | email: isEmail("Invalid email"), 31 | password: hasLength({ min: 6 }, "Password must contain at least 6 chars"), 32 | }, 33 | }); 34 | const { mutateAsync, isLoading } = useMutation({ 35 | mutationFn: async (values: typeof initialValues) => { 36 | const { email, password, first_name, last_name } = values; 37 | const res = await supabaseClient.auth.signUp({ 38 | email, 39 | password, 40 | options: { 41 | emailRedirectTo: absoluteUrl("/auth/callback"), 42 | data: { 43 | first_name, 44 | last_name, 45 | } satisfies UserMetadata, 46 | }, 47 | }); 48 | 49 | if (res.error) { 50 | throw res.error; 51 | } 52 | 53 | return res; 54 | }, 55 | }); 56 | 57 | const handleSubmit = async (values: typeof initialValues) => { 58 | try { 59 | await mutateAsync(values); 60 | reset(); 61 | toast.success( 62 | "We just sent you the confirmation mail. Please open the link and attempt to log in." 63 | ); 64 | } catch (err) { 65 | if (err instanceof AuthError) { 66 | toast.error(err.message); 67 | } 68 | } 69 | }; 70 | 71 | return ( 72 | 73 | 74 | Sign up 75 | 76 |
77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | Already have an account?{" "} 87 | 88 | Sign in 89 | 90 | 91 | 92 |
93 | ); 94 | } 95 | -------------------------------------------------------------------------------- /app/dashboard/blog/[blogId]/BlogProvider.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import { useBaseEditor } from "@/lib/editor"; 4 | import { AppProps, Blog } from "@/types"; 5 | import { UseFormReturnType, useForm } from "@mantine/form"; 6 | import { useDebouncedValue } from "@mantine/hooks"; 7 | import { useUpdate } from "@refinedev/core"; 8 | import { Editor } from "@tiptap/react"; 9 | import { useRouter, useSearchParams } from "next/navigation"; 10 | import React from "react"; 11 | import ImportBlogModal from "./components/ImportBlogModal"; 12 | 13 | interface BlogContextInitialState { 14 | blog: Blog; 15 | form: UseFormReturnType; 16 | isSaving: boolean; 17 | isSavingSuccess: boolean; 18 | isEditingMode: boolean; 19 | editor: Editor | null; 20 | } 21 | 22 | const BlogContext = React.createContext(undefined); 23 | 24 | interface BlogEditForm { 25 | title: string; 26 | content: string; 27 | contentMarkdown: string; 28 | tags: string[]; 29 | } 30 | 31 | export default function BlogProvider(props: AppProps & { blog: Blog }) { 32 | const { children, blog } = props; 33 | const form = useForm({ 34 | initialValues: { 35 | title: blog.title, 36 | content: blog.content || "", 37 | contentMarkdown: blog.contentMarkdown || "", 38 | tags: (blog.tags as string[]) || [], 39 | }, 40 | }); 41 | const [debouncedValues] = useDebouncedValue(form.values, 1000); 42 | const [isFirstTime, setFirstTime] = React.useState(true); 43 | const searchParams = useSearchParams(); 44 | const isEditingMode = searchParams.get("type") === "edit"; 45 | const editor = useBaseEditor({ 46 | content: blog.content, 47 | editable: isEditingMode, 48 | onUpdate({ editor }) { 49 | form.setFieldValue("content", editor.getHTML()); 50 | form.setFieldValue("contentMarkdown", editor.storage.markdown.getMarkdown()); 51 | }, 52 | onFocus({ editor, event }) { 53 | if (event.isTrusted) { 54 | form.setFieldValue("content", editor.getHTML()); 55 | form.setFieldValue("contentMarkdown", editor.storage.markdown.getMarkdown()); 56 | } 57 | }, 58 | }); 59 | const { mutateAsync, isLoading, isSuccess } = useUpdate(); 60 | const router = useRouter(); 61 | 62 | const saveBlogChanges = React.useCallback( 63 | async (values: BlogEditForm) => { 64 | try { 65 | await mutateAsync({ 66 | resource: "blogs", 67 | id: blog.id, 68 | values, 69 | successNotification: false, 70 | }); 71 | } catch (err) { 72 | // 73 | } 74 | }, 75 | [blog.id, mutateAsync] 76 | ); 77 | 78 | // * Autosave the changes 79 | React.useEffect(() => { 80 | // When the page renders for the first time, don't save 81 | // And only if its in editing mode 82 | if (!isFirstTime && isEditingMode) { 83 | saveBlogChanges(debouncedValues); 84 | } 85 | setFirstTime(false); 86 | // eslint-disable-next-line react-hooks/exhaustive-deps 87 | }, [debouncedValues, saveBlogChanges]); 88 | 89 | React.useEffect(() => { 90 | /** 91 | * Update content of the route before leaving the page 92 | * So if the user comes back, he sees the updates he made last time 93 | * Not the old one 94 | */ 95 | return () => router.refresh(); 96 | }, [router]); 97 | 98 | const contextValue: BlogContextInitialState = { 99 | blog, 100 | form, 101 | isSaving: isLoading, 102 | isSavingSuccess: isSuccess, 103 | isEditingMode, 104 | editor, 105 | }; 106 | 107 | return ( 108 | 109 | {children} 110 | 111 | ); 112 | } 113 | 114 | export function useBlogContext() { 115 | const blogContext = React.useContext(BlogContext); 116 | 117 | if (blogContext === undefined) { 118 | throw new Error("This hook must be used within specified context"); 119 | } 120 | 121 | return blogContext; 122 | } 123 | -------------------------------------------------------------------------------- /app/dashboard/blog/[blogId]/components/BlogActions.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import { Stack } from "@mantine/core"; 3 | import { useBlogContext } from "../BlogProvider"; 4 | import PubRepBlog from "./PubRepBlog"; 5 | 6 | export default function BlogActions() { 7 | const { blog } = useBlogContext(); 8 | return ( 9 | 10 | 11 | 12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /app/dashboard/blog/[blogId]/components/BlogContent.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import MarkdownEditor from "@/components/MarkdownEditor"; 3 | import { Box } from "@mantine/core"; 4 | import React from "react"; 5 | import { useBlogContext } from "../BlogProvider"; 6 | 7 | export default function BlogContent() { 8 | const { isEditingMode, editor } = useBlogContext(); 9 | React.useEffect(() => { 10 | if (editor) { 11 | editor.setOptions({ editable: isEditingMode }); 12 | } 13 | }, [editor, isEditingMode]); 14 | return ( 15 | 16 | 17 | 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /app/dashboard/blog/[blogId]/components/BlogHeader.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import { useDeleteBlogContext } from "@/app/dashboard/providers/delete-blog"; 4 | import Icon from "@/components/Icon"; 5 | import { generateSlug } from "@/helpers/blog"; 6 | import { ActionIcon, Anchor, Badge, Breadcrumbs, Group, Menu, Text } from "@mantine/core"; 7 | import { saveAs } from "file-saver"; 8 | import Link from "next/link"; 9 | import React from "react"; 10 | import { useBlogContext } from "../BlogProvider"; 11 | import { useImportBlog } from "./ImportBlogModal"; 12 | 13 | export default function BlogHeader() { 14 | const { blog, isEditingMode } = useBlogContext(); 15 | const { openDeleteBlogModal } = useDeleteBlogContext(); 16 | const { open } = useImportBlog(); 17 | 18 | const handleDeleteDraft = () => { 19 | openDeleteBlogModal(blog.id); 20 | }; 21 | 22 | return ( 23 | 24 | 25 | 26 | Blogs 27 | 28 | 29 | {blog.title} 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | {isEditingMode ? ( 42 | } 44 | component={Link} 45 | href={`/dashboard/blog/${blog.id}`} 46 | > 47 | Reading mode 48 | 49 | ) : ( 50 | } 52 | component={Link} 53 | href={{ pathname: `/dashboard/blog/${blog.id}`, search: "type=edit" }} 54 | > 55 | Edit 56 | 57 | )} 58 | }> 59 | Delete draft 60 | 61 | 62 | Export 63 | 64 | }>Export as HTML 65 | 66 | 67 | }>Export as Markdown 68 | 69 | 70 | Import 71 | open("html")} icon={}> 72 | Import from HTML 73 | 74 | open("markdown")} icon={}> 75 | Import from Markdown 76 | 77 | 78 | 79 | 80 | 81 | ); 82 | } 83 | 84 | function ExportBlog(props: { children: React.ReactElement; format: "html" | "markdown" }) { 85 | const { children, format } = props; 86 | const { editor, blog } = useBlogContext(); 87 | const handleExport = () => { 88 | if (!editor) return; 89 | 90 | const mimeTypes: Record<"html" | "markdown", string> = { 91 | html: "text/html;charset=utf-8;", 92 | markdown: "text/markdown;charset=utf-8;", 93 | }; 94 | const fileExtensions = { 95 | html: "", 96 | markdown: ".md", 97 | }; 98 | const fileExtension = fileExtensions[format]; 99 | const mimeType = mimeTypes[format]; 100 | 101 | const html = editor.getHTML(); 102 | const markdown = editor.storage.markdown.getMarkdown(); 103 | 104 | let content; 105 | 106 | if (format === "markdown") { 107 | content = markdown; 108 | } else { 109 | content = html; 110 | } 111 | 112 | const blob = new Blob([content], { type: mimeType }); 113 | saveAs(blob, `${generateSlug(blog.title)}${fileExtension}`); 114 | }; 115 | const triggeredChildren = React.cloneElement(children, { onClick: handleExport }); 116 | return triggeredChildren; 117 | } 118 | 119 | function BlogSavingStatus() { 120 | const { isSaving, isSavingSuccess } = useBlogContext(); 121 | if (isSaving) { 122 | return ( 123 | 124 | Saving... 125 | 126 | ); 127 | } 128 | if (isSavingSuccess) { 129 | return ( 130 | 131 | Saved 132 | 133 | ); 134 | } 135 | return <>; 136 | } 137 | -------------------------------------------------------------------------------- /app/dashboard/blog/[blogId]/components/BlogPrimaryDetails.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import { badgeStyles } from "@/app/dashboard/components/Blogs"; 3 | import DevToLogoSrc from "@/assets/logos/dev-to.png"; 4 | import HashNodeLogoSrc from "@/assets/logos/hashnode.png"; 5 | import Icon, { IconNames } from "@/components/Icon"; 6 | import useMediaQuery from "@/hooks/useMediaQuery"; 7 | import { formatDate } from "@/lib/utils"; 8 | import { AppProps } from "@/types"; 9 | import { 10 | Badge, 11 | CloseButton, 12 | Flex, 13 | Group, 14 | MultiSelect, 15 | MultiSelectValueProps, 16 | Stack, 17 | Text, 18 | Textarea, 19 | useMantineTheme, 20 | } from "@mantine/core"; 21 | import Image from "next/image"; 22 | import React from "react"; 23 | import { useBlogContext } from "../BlogProvider"; 24 | 25 | export default function BlogPrimaryDetails() { 26 | const [hydrated, setHydrated] = React.useState(false); 27 | const { form, isEditingMode, blog } = useBlogContext(); 28 | const { isOverSm } = useMediaQuery(); 29 | const badgeStyle = badgeStyles[blog.status]; 30 | 31 | React.useEffect(() => { 32 | setHydrated(true); 33 | }, []); 34 | 35 | if (!hydrated) { 36 | return <>; 37 | } 38 | 39 | return ( 40 | 41 | 42 |