mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-10 04:47:11 +02:00
disable limited tier if already used
This commit is contained in:
parent
0dcfeb3587
commit
f37be774a6
4 changed files with 35 additions and 14 deletions
|
@ -10,6 +10,7 @@ import { users } from "@server/db/schema";
|
||||||
|
|
||||||
export type IsSupporterKeyVisibleResponse = {
|
export type IsSupporterKeyVisibleResponse = {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
|
tier?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const USER_LIMIT = 5;
|
const USER_LIMIT = 5;
|
||||||
|
@ -29,16 +30,17 @@ export async function isSupporterKeyVisible(
|
||||||
const [numUsers] = await db.select({ count: count() }).from(users);
|
const [numUsers] = await db.select({ count: count() }).from(users);
|
||||||
|
|
||||||
if (numUsers.count > USER_LIMIT) {
|
if (numUsers.count > USER_LIMIT) {
|
||||||
|
logger.debug(
|
||||||
|
`User count ${numUsers.count} exceeds limit ${USER_LIMIT}`
|
||||||
|
);
|
||||||
visible = true;
|
visible = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(`Supporter key visible: ${visible}`);
|
|
||||||
logger.debug(JSON.stringify(key));
|
|
||||||
|
|
||||||
return sendResponse<IsSupporterKeyVisibleResponse>(res, {
|
return sendResponse<IsSupporterKeyVisibleResponse>(res, {
|
||||||
data: {
|
data: {
|
||||||
visible
|
visible,
|
||||||
|
tier: key?.tier || undefined
|
||||||
},
|
},
|
||||||
success: true,
|
success: true,
|
||||||
error: false,
|
error: false,
|
||||||
|
|
|
@ -32,12 +32,13 @@ export default async function RootLayout({
|
||||||
|
|
||||||
let supporterData = {
|
let supporterData = {
|
||||||
visible: true
|
visible: true
|
||||||
};
|
} as any;
|
||||||
|
|
||||||
const res = await priv.get<
|
const res = await priv.get<
|
||||||
AxiosResponse<IsSupporterKeyVisibleResponse>
|
AxiosResponse<IsSupporterKeyVisibleResponse>
|
||||||
>("supporter-key/visible");
|
>("supporter-key/visible");
|
||||||
supporterData.visible = res.data.data.visible;
|
supporterData.visible = res.data.data.visible;
|
||||||
|
supporterData.tier = res.data.data.tier;
|
||||||
|
|
||||||
const version = env.app.version;
|
const version = env.app.version;
|
||||||
|
|
||||||
|
|
|
@ -218,7 +218,9 @@ export default function SupporterStatus() {
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card>
|
<Card
|
||||||
|
className={`${supporterStatus?.tier === "Limited Supporter" ? "opacity-50" : ""}`}
|
||||||
|
>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>Limited Supporter</CardTitle>
|
<CardTitle>Limited Supporter</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
|
@ -246,14 +248,29 @@ export default function SupporterStatus() {
|
||||||
</ul>
|
</ul>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
<CardFooter>
|
<CardFooter>
|
||||||
<Link
|
{supporterStatus?.tier !==
|
||||||
href="https://www.google.com"
|
"Limited Supporter" ? (
|
||||||
target="_blank"
|
<Link
|
||||||
rel="noopener noreferrer"
|
href="https://www.google.com"
|
||||||
className="w-full"
|
target="_blank"
|
||||||
>
|
rel="noopener noreferrer"
|
||||||
<Button className="w-full">Buy</Button>
|
className="w-full"
|
||||||
</Link>
|
>
|
||||||
|
<Button className="w-full">
|
||||||
|
Buy
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<Button
|
||||||
|
className="w-full"
|
||||||
|
disabled={
|
||||||
|
supporterStatus?.tier ===
|
||||||
|
"Limited Supporter"
|
||||||
|
}
|
||||||
|
>
|
||||||
|
Buy
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
</CardFooter>
|
</CardFooter>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { createContext } from "react";
|
||||||
|
|
||||||
export type SupporterStatus = {
|
export type SupporterStatus = {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
|
tier?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type SupporterStatusContextType = {
|
type SupporterStatusContextType = {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue