Skip to content

Commit

Permalink
Merge pull request #165 from aitok-ai/lihang/pay_wording
Browse files Browse the repository at this point in the history
Add subscription into Profile page
  • Loading branch information
lihyin authored Dec 22, 2023
2 parents 5530c6d + 89aebdc commit 310171f
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/models/schema/userSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const userSchema = mongoose.Schema(
},
proMemberExpiredAt: {
type: Date,
default: '',
default: new Date(),
},
},
{ timestamps: true },
Expand Down
2 changes: 1 addition & 1 deletion api/server/routes/ask/openAI.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ router.post('/', validateEndpoint, buildEndpointOption, setHeaders, async (req,
let dailyQuota = quota[endpointOption.modelOptions.model].toFixed(0);
if (messagesCount >= dailyQuota) {
throw new Error(
`超出了您的使用额度(${endpointOption.modelOptions.model}模型每天${dailyQuota}条消息)。由于需要支付越来越多、每月上万元的API费用,如果您经常使用我们的服务,请通过此网页购买更多额度、支持我们持续提供GPT服务:https://iaitok.com`,
`超出了您的使用额度(${endpointOption.modelOptions.model}模型每天${dailyQuota}条消息)。由于需要支付越来越多、每月上万元的API费用,如果您经常使用我们的服务,请通过此网页购买更多额度、支持我们持续提供GPT服务:https://iaitok.com 目前限时半价优惠每月60元`,
);
}
}
Expand Down
25 changes: 25 additions & 0 deletions client/src/components/Profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function ProfileContent() {
const [isFollower, setIsFollower] = useState<boolean>(false);
const [numOfFollowers, setNumOfFollowers] = useState<number>(0);
const [numOfFollowing, setNumOfFollowing] = useState<number>(0);
const [proMemberExpiredAt, setProMemberExpiredAt] = useState<Date>(new Date());
const [editMode, setEditMode] = useState<boolean>(false);
const [bio, setBio] = useState(initialBio || '');
// const [profession, setProfession] = useState(initialProfession || '');
Expand Down Expand Up @@ -247,6 +248,12 @@ function ProfileContent() {
} else {
setNumOfFollowing(0);
}

if (getUserByIdQuery.data.proMemberExpiredAt) {
setProMemberExpiredAt(new Date(getUserByIdQuery.data?.proMemberExpiredAt));
} else {
setProMemberExpiredAt(new Date());
}
}
}, [getUserByIdQuery.isSuccess, getUserByIdQuery.data, user]);

Expand Down Expand Up @@ -445,6 +452,24 @@ function ProfileContent() {
</button>
)}
</div>
{/* Subscription */}
{userId === user?.id ? (
proMemberExpiredAt && proMemberExpiredAt > new Date() ? (
// Current user: show subscription
<div className="w-full rounded-lg p-6 dark:text-gray-200">
<div className="pl-7">
{localize('com_ui_pro_member_expired_at')}: {proMemberExpiredAt.getFullYear()}-
{proMemberExpiredAt.getMonth() + 1}-{proMemberExpiredAt.getDate()}
</div>
</div>
) : (
<div className="w-full rounded-lg p-6 dark:text-gray-200">
<div className="pl-7">{localize('com_ui_free_member')}</div>
</div>
)
) : (
<div></div>
)}

{/* User bio */}
{userId === user?.id ? (
Expand Down
2 changes: 2 additions & 0 deletions client/src/localization/languages/Eng.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export default {
com_ui_follow: 'Follow',
com_ui_followers: 'Followers',
com_ui_following: 'Following',
com_ui_pro_member_expired_at: 'Pro Member. Expired On',
com_ui_free_member: 'Free Member',
com_ui_about_yourself: 'About Yourself',
com_ui_profession: 'Profession',
com_ui_share_profile: 'Share Profile',
Expand Down
2 changes: 2 additions & 0 deletions client/src/localization/languages/Zh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export default {
com_ui_follow: '关注',
com_ui_followers: '粉丝',
com_ui_following: '关注',
com_ui_pro_member_expired_at: 'Pro用户. 过期日期',
com_ui_free_member: '免费用户',
com_ui_about_yourself: '关于自己',
com_ui_profession: '职业',
com_ui_share_profile: '分享主页',
Expand Down
2 changes: 1 addition & 1 deletion packages/data-provider/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export type TUser = {
biography: string;
followers: object;
following: object;
proMemberExpiredAt: string;
proMemberExpiredAt: Date;
};

export type TGetConversationsResponse = {
Expand Down

0 comments on commit 310171f

Please sign in to comment.