Skip to content

Commit

Permalink
feat(web): add signup with invitecode (#1144)
Browse files Browse the repository at this point in the history
* feat(web): add signup with invitecode
---------

Co-authored-by: allence <lizhenq2009@gmail.com>
  • Loading branch information
newfish-cmyk and LeezQ authored May 21, 2023
1 parent 4929fe3 commit 78a671c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions web/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,5 +418,6 @@
},
"ChatGPT example": "ChatGPT example",
"LinkCopied": "Link Copied",
"create success": "create success",
"ServerStatus": "STATUS"
}
1 change: 1 addition & 0 deletions web/public/locales/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,5 +418,6 @@
},
"ChatGPT example": "ChatGPT 示例",
"LinkCopied": "链接复制成功",
"create success": "创建成功",
"ServerStatus": "服务状态"
}
1 change: 1 addition & 0 deletions web/public/locales/zh/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -418,5 +418,6 @@
},
"ChatGPT example": "ChatGPT 示例",
"LinkCopied": "链接复制成功",
"create success": "创建成功",
"ServerStatus": "服务状态"
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const CreateModal = (props: { functionItem?: any; children?: React.ReactElement
}

if (!res.error) {
showSuccess(isEdit ? "update success" : "create success");
showSuccess(isEdit ? t("update success") : t("create success"));
onClose();
store.setCurrentFunction(res.data);
reset(defaultValues);
Expand Down
28 changes: 28 additions & 0 deletions web/src/pages/auth/signup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,32 @@ export default function SignUp() {
const [countdown, setCountdown] = useState(60);
const [isShowPassword, setIsShowPassword] = useState(false);

let inviteCode = new URLSearchParams(window.location.search).get("code");

if (inviteCode) {
const now = new Date();
const expirationDays = 7;
const expiration = new Date(now.getTime() + expirationDays * 24 * 60 * 60 * 1000);

const item = {
value: inviteCode,
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 {
inviteCode = data.value;
}
}
}

const {
register,
getValues,
Expand Down Expand Up @@ -91,11 +117,13 @@ export default function SignUp() {
code: data.validationCode,
username: data.account,
password: data.password,
inviteCode: inviteCode,
type: "Signup",
}
: {
username: data.account,
password: data.password,
inviteCode: inviteCode,
type: "Signup",
};

Expand Down
4 changes: 2 additions & 2 deletions web/src/pages/home/mods/List/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ function List(props: { appListQuery: any; setShouldRefetch: any }) {
<p
className={clsx(
"mt-1",
dayjs().add(3, "day").isAfter(dayjs(item.subscription.expiredAt))
dayjs().add(3, "day").isAfter(dayjs(item.subscription?.expiredAt))
? "text-red-500"
: "",
)}
>
{t("EndTime")}: {formatDate(item.subscription.expiredAt)}
{t("EndTime")}: {formatDate(item.subscription?.expiredAt)}
<CreateAppModal application={item} type="renewal">
<a
className="invisible ml-2 text-primary-500 group-hover:visible group-hover:inline-block"
Expand Down

0 comments on commit 78a671c

Please sign in to comment.