Skip to content

Commit ed10228

Browse files
authored
Merge pull request #12 from RizkyRajitha/dev
Dev
2 parents 3c15476 + 31f4636 commit ed10228

File tree

12 files changed

+139
-51
lines changed

12 files changed

+139
-51
lines changed

README.md

Lines changed: 61 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Linkin · [![DeepScan grade](https://deepscan.io/api/teams/14086/projects/17178/branches/386441/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=14086&pid=17178&bid=386441) [![codecov](https://codecov.io/gh/RizkyRajitha/linkin/branch/master/graph/badge.svg?token=DPE3YVUYUW)](https://codecov.io/gh/RizkyRajitha/linkin) ![license](https://img.shields.io/github/license/rizkyrajitha/linkin??style=plastic)
66

7-
## Linkin is a customizable self hosted link in the bio platform.
7+
## Linkin is a customizable self-hosted link tree platform.
88

99
<!-- <br>
1010
<br>
@@ -13,7 +13,7 @@
1313
### You have absolute control
1414
1515
### Add your custom fonts
16-
### No branding , it's yours
16+
### No branding, it's yours
1717
1818
### You control your data . -->
1919

@@ -22,38 +22,36 @@
2222

2323
## Deploy with Vercel
2424

25-
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2FRizkyRajitha%2Flinkin&env=DBURL&envDescription=PostgreSQL%20database%20URL&demo-title=Linkin%20&demo-description=Linkin%20is%20a%20customizable%20self%20hosted%20link%20in%20the%20bio%20platform%20.%20And%20it's%20ready%20for%20you)
25+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2FRizkyRajitha%2Flinkin&env=DBURL,KEY&demo-title=Linkin&demo-description=Linkin%20is%20a%20customizable%20self%20hosted%20link%20tree%20platform%20%2C%20And%20we%20are%20ready%20to%20roll)
26+
27+
<!-- [![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https%3A%2F%2Fgithub.com%2FRizkyRajitha%2Flinkin&env=DBURL&envDescription=PostgreSQL%20database%20URL&demo-title=Linkin%20&demo-description=Linkin%20is%20a%20customizable%20self%20hosted%20link%20in%20the%20bio%20platform%20.%20And%20it's%20ready%20for%20you) -->
2628

2729
## Deploy with Heroku
2830

29-
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/RizkyRajitha/linkin&env[DBURL]=postgresdburl&env[KEY]=123)
31+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/RizkyRajitha/linkin)
32+
33+
<!-- [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/RizkyRajitha/linkin&env[DBURL]=postgresdburl&env[KEY]=123) -->
3034

31-
![Screenshot_2021-05-22 LinkIn's Link In The Bio Page](https://user-images.githubusercontent.com/38534289/119221911-4ca94f80-bb0f-11eb-94ff-31f1c3a51d06.png)
35+
![Screenshot_2021-05-22 LinkIn's Link tree Page](https://user-images.githubusercontent.com/38534289/119221911-4ca94f80-bb0f-11eb-94ff-31f1c3a51d06.png)
3236

3337
![Screenshot_2021-05-22 Linkin Dashboard](https://user-images.githubusercontent.com/38534289/119221942-7d898480-bb0f-11eb-9175-5e139fa57f0a.png)
3438

3539
![Screenshot_2021-05-22 Linkin Dashboard](https://user-images.githubusercontent.com/38534289/119221939-7c585780-bb0f-11eb-944f-514beb5573b7.png)
3640

3741
### Getting started
3842

39-
- host in vercel
40-
- set vercel environment variables
43+
- Hosting
44+
- set environment variables
45+
- **Mandatory**
4146
- `DBURL` - **Postgres** database url
4247
- `KEY` - random secret key
43-
- after successfully deploying visit `youdomain/admin` to view admin login
44-
- use default login credentials
45-
- username = `admin`
46-
- password = `linkin123`
47-
- after a successfull login you will be able to see above admin dashboard.
48-
49-
### Build with
50-
51-
- [NextJs](https://nextjs.org/)
52-
- [Postgres](https://www.postgresql.org/)
53-
54-
### Host in
55-
56-
- [Vercel](https://vercel.com/) .
48+
- **Optional**
49+
- `changePasswordEnabled` - for showcase so that anonymous users cant change the password . default set to `true` .
50+
- after successfully deploying visit `youdomain/admin` to view admin login
51+
- use default login credentials
52+
- username = `admin`
53+
- password = `linkin123`
54+
- after a successfull login you will be able to see above admin dashboard.
5755

5856
### Developing locally
5957

@@ -71,7 +69,7 @@ exports.DBURLLOCAL = "postgres://linkin:123@localhost:5432/linkin";
7169
exports.SECRETKEY = "123";
7270
```
7371

74-
#### Clone and install dependancies
72+
#### Clone and install dependencies
7573

7674
```
7775
git clone https://github.com/RizkyRajitha/linkin.git
@@ -81,7 +79,7 @@ npm i
8179

8280
#### Database migration
8381

84-
**you must have postgres database setup locally**
82+
**you must have Postgres database setup locally**
8583

8684
```
8785
node scripts/migrate.js
@@ -93,15 +91,41 @@ node scripts/migrate.js
9391
npm run dev
9492
```
9593

94+
### Build with
95+
96+
- [Next.Js](https://nextjs.org/) .
97+
<!-- - ![Nextjs logo](https://upload.wikimedia.org/wikipedia/commons/thumb/8/8e/Nextjs-logo.svg/800px-Nextjs-logo.svg.png) -->
98+
- [Postgres](https://www.postgresql.org/) .
99+
100+
### Currently supported hosting in
101+
102+
- [Vercel](https://vercel.com/) .
103+
- [Heroku](https://heroku.com/) .
104+
105+
<!-- ### Build with
106+
107+
- [NextJs](https://nextjs.org/)
108+
- <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8e/Nextjs-logo.svg/800px-Nextjs-logo.svg.png" width="150" title="nextjs logo">
109+
110+
- [Postgres](https://www.postgresql.org/)
111+
- <img src="https://upload.wikimedia.org/wikipedia/commons/2/29/Postgresql_elephant.svg" width="150" title="postgres db logo">
112+
113+
### Host in
114+
115+
- [Vercel](https://vercel.com/) .
116+
- <img src="https://assets.vercel.com/image/upload/q_auto/front/zeit/og.png" width="150" title="vercel logo">
117+
- [Heroku](https://heroku.com/) .
118+
- <img src="https://brand.heroku.com/static/media/heroku-logotype-horizontal.81c49462.svg" width="150" title="heroku logo"> -->
119+
96120
<!-- todo
97121
98122
v 0.2.0
99123
100-
add react toast
124+
add react toast
101125
102-
add sweet altert
126+
add sweet alert ✅
103127
104-
add delete links function
128+
add delete links function
105129
106130
add link data update to link card ✅
107131
@@ -110,39 +134,37 @@ add react context ✅
110134
gfx minorn updates ✅
111135
112136
137+
v 0.2.1
138+
139+
140+
add heroku deploy ✅
113141
142+
add change password ✅
114143
144+
form submit better ✅
115145
146+
backgroud gradients
116147
148+
backgroud images
117149
118150
151+
photo boarder changeble .
152+
119153
120154
add update form to update page data
121155
add index with avatar url and other data
122-
add update form to update links
123-
logout button navbar -
156+
124157
125158
add forms
126159
genaral
127160
links
128161
colors
129162
130-
fix update function with object keys
131-
132-
seperate alert componnet
133-
134-
photo boarder changeble .
135-
136-
137-
138163
139164
140-
add update link route
141165
142-
add delete link route
143166
144167
145-
usefetch hook
146168
147169
better save stratergy
148170
https://fonts.googleapis.com/css2?family=Source+Code+Pro&display=swap

app.json

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Linkin",
33
"repository": "https://github.com/RizkyRajitha/linkin",
4-
"description": "Linkin is a customizable self hosted link in the bio platform",
4+
"description": "Linkin is a customizable self hosted link tree platform",
55
"logo": "https://res.cloudinary.com/dijjqfsto/image/upload/v1621666671/linkin_logo_1_jcuvr3.png",
66
"keywords": [
77
"next",
@@ -12,5 +12,15 @@
1212
"react",
1313
"node",
1414
"postgres"
15-
]
15+
],
16+
"env": {
17+
"KEY": {
18+
"description": "Random secret key.This gets generated automatically",
19+
"value": ""
20+
},
21+
"DBURL": {
22+
"description": "Postgres database url",
23+
"value": ""
24+
}
25+
}
1626
}

components/formwrapper.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ const PUBLICURL =
1717
const endpoint =
1818
process.env.NODE_ENV === "production" ? `` : "http://localhost:3000";
1919

20+
const changePasswordEnabled = process.env.changePasswordEnabled || true;
21+
2022
function Formwrapper({ pageData, updatedPageData }) {
2123
const router = useRouter();
2224

@@ -114,6 +116,7 @@ function Formwrapper({ pageData, updatedPageData }) {
114116
className={`btn btn-outline-primary logout-btn ${
115117
styles.logoutbtn
116118
} ${activeForm === "passwordchangeform" ? "active" : ""} `}
119+
disabled={!changePasswordEnabled}
117120
onClick={() => {
118121
setactiveForm("passwordchangeform");
119122
}}

components/linkcard.js

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
import { useCallback, useEffect, useRef } from "react";
1+
import { useCallback, useEffect, useRef, useState } from "react";
22
import { useForm } from "react-hook-form";
33

44
import debounce from "lodash.debounce";
55

66
export default function LinkCard({ item, updateLink, deleteLink, loading }) {
77
const refSubmitButtom = useRef(null);
8+
const [cardInfo, setCardInfo] = useState(item);
89

910
const {
1011
register,
@@ -19,12 +20,30 @@ export default function LinkCard({ item, updateLink, deleteLink, loading }) {
1920
// console.log(item);
2021

2122
// cancel the debounce function when submited by enter
22-
debouncedSaveLinkData.cancel();
23+
// debouncedSaveLinkData.cancel();
24+
25+
// console.warn("!!!!!!!!!!!!!!!!!!!!!!!!!");
26+
// console.log(item);
27+
// console.log(cardInfo);
28+
// console.log(cardInfo.id);
2329

2430
// reset when the linkdata is change to the form update with new values
25-
if (item) {
31+
if (cardInfo.id === undefined && item.id) {
32+
// console.log("reset with item");
33+
reset(item);
34+
setCardInfo(item);
35+
}
36+
// reset when the link is deleted to the card will show differert value
37+
if (cardInfo.id !== item.id) {
38+
// console.log("reset after delete");
2639
reset(item);
40+
setCardInfo(item);
2741
}
42+
43+
// reset when the linkdata is change to the form update with new values
44+
// if (item) {
45+
// reset(item);
46+
// }
2847
}, [item]);
2948

3049
watch((data, { type }) => {
@@ -36,20 +55,28 @@ export default function LinkCard({ item, updateLink, deleteLink, loading }) {
3655
debouncedSaveLinkData();
3756
});
3857

58+
// debounced function to save the data after 1.5 seconds
3959
const debouncedSaveLinkData = useCallback(
4060
debounce(() => {
4161
refSubmitButtom?.current?.click();
4262
}, 1500),
4363
[]
4464
);
4565

66+
const submitAction = (data) => {
67+
// when the form is submited by enter , the debounced action is canceled to avoid uplicate debounce
68+
debouncedSaveLinkData.cancel();
69+
// console.log(data);
70+
updateLink(data);
71+
};
72+
4673
return (
4774
<>
4875
<div className="card mt-3">
4976
<div className="card-body py-2 px-4">
5077
{/* {console.log(errors)} */}
5178
{/* {JSON.stringify(item)} */}
52-
<form onSubmit={handleSubmit(updateLink)}>
79+
<form onSubmit={handleSubmit(submitAction)}>
5380
<div className="form-check form-switch d-grid gap-2 d-md-flex justify-content-md-end">
5481
<input
5582
className="form-check-input"

components/linkinthebiopage.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect } from "react";
22
import { isEmptry } from "../lib/side";
3+
// import Image from "next/image";
34

45
export default function Home({
56
handlerText,
@@ -47,7 +48,7 @@ export default function Home({
4748
<div className="outterwrap">
4849
<div className="wrap">
4950
<div className="profile">
50-
<img src={avatarUrl} className="photo" />
51+
{/* <img src={avatarUrl} className="photo" /> */}
5152
<a className="handlerLink" href={`${handlerLink}`} target="_blank">
5253
<span className="handlerText">{handlerText}</span>
5354
</a>

components/passwordchangeform.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const PasswordChangeForm = () => {
1313
register,
1414
handleSubmit,
1515
watch,
16+
reset,
1617
formState: { errors },
1718
} = useForm();
1819
const router = useRouter();
@@ -49,6 +50,7 @@ const PasswordChangeForm = () => {
4950
draggable: true,
5051
progress: undefined,
5152
});
53+
reset();
5254
setloading(false);
5355
return;
5456
}
@@ -65,6 +67,7 @@ const PasswordChangeForm = () => {
6567
await logout();
6668
} catch (error) {
6769
console.log(error);
70+
reset();
6871
toast.error(`Error : ${error.message}`, {
6972
position: "bottom-left",
7073
autoClose: 5000,

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.2.0",
44
"private": true,
55
"license": "MIT",
6-
"description": "Linkin is a customizable self hosted link in the bio platform",
6+
"description": "Linkin is a customizable self hosted link tree platform",
77
"logo": "https://res.cloudinary.com/dijjqfsto/image/upload/v1621666671/linkin_logo_1_jcuvr3.png",
88
"repository": {
99
"type": "git",

pages/api/changepassword.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@ import bcrypt from "bcrypt";
33
import { jwtAuth, use } from "../../middleware/middleware";
44
import { changePassword, getUser } from "../../lib/dbfunc";
55

6+
const changePasswordEnabled = process.env.changePasswordEnabled || true;
67
const saltRounds = 10;
78

89
async function handler(req, res) {
910
if (req.method !== "POST") {
1011
res.status(400).send("method not allowed");
1112
return;
1213
}
14+
15+
if (!changePasswordEnabled) {
16+
res.status(401).send("Change Password not allowed");
17+
return;
18+
}
19+
1320
try {
1421
// Run the middleware
1522
await use(req, res, jwtAuth);

0 commit comments

Comments
 (0)