-
-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): add invitecode to homepage and login (#1170)
- Loading branch information
1 parent
34d85dd
commit 6f604be
Showing
4 changed files
with
49 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
const useInviteCode = () => { | ||
const [inviteCode, setInviteCode] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
let code = new URLSearchParams(window.location.search).get("code"); | ||
|
||
if (code) { | ||
const now = new Date(); | ||
const expirationDays = 7; | ||
const expiration = new Date(now.getTime() + expirationDays * 24 * 60 * 60 * 1000); | ||
|
||
const item = { | ||
value: code, | ||
expiration: expiration.getTime(), | ||
}; | ||
|
||
localStorage.setItem("inviteCode", JSON.stringify(item)); | ||
} else { | ||
const item = localStorage.getItem("inviteCode"); | ||
|
||
if (item) { | ||
const data = JSON.parse(item); | ||
if (new Date().getTime() > data.expiration) { | ||
localStorage.removeItem("inviteCode"); | ||
} else { | ||
code = data.value; | ||
} | ||
} | ||
} | ||
|
||
setInviteCode(code); | ||
}, []); | ||
|
||
return inviteCode; | ||
}; | ||
|
||
export default useInviteCode; |
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