mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-18 15:44:36 +00:00
premium lock component (#381)
**Basic Usage** (just wrap it over any feature you want to premium
lock):
`<PremiumLock requiredPlan="any">
<div>Content for premium users</div>
</PremiumLock>`
This component still needs to be linked with the API.
This commit is contained in:
1 parent
6633a0d0d8
commit
b538a634bb
3 files changed
+135
-37
No files matched your search
@@ -0,0 +1,92 @@
|
||||
import { Link } from "react-router-dom";
|
||||
import React from "react";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { faLock } from "@fortawesome/pro-solid-svg-icons";
|
||||
|
||||
interface PremiumLockProps {
|
||||
requiredPlan?: "any" | "plus" | "pro" | "elite";
|
||||
children: React.ReactNode;
|
||||
plural?: boolean; // if the message should be plural for multiple features
|
||||
}
|
||||
|
||||
// replace with api to check
|
||||
const sessionSubscriptions = {
|
||||
hasPaidFeatures: () => true, // if has any paid features at all
|
||||
hasActivePlusSubscription: () => false, // if has plus or not
|
||||
hasActiveProSubscription: () => false, // if has pro or not
|
||||
hasActiveEliteSubscription: () => false, // if has elite or not
|
||||
};
|
||||
|
||||
export default function PremiumLock({
|
||||
requiredPlan = "plus",
|
||||
plural = false,
|
||||
children,
|
||||
}: PremiumLockProps) {
|
||||
const getPlanMessage = (plan: string) => {
|
||||
switch (plan) {
|
||||
case "any":
|
||||
return "premium";
|
||||
case "plus":
|
||||
return "premium plus";
|
||||
case "pro":
|
||||
return "premium pro";
|
||||
case "elite":
|
||||
return "premium elite";
|
||||
default:
|
||||
return "premium";
|
||||
}
|
||||
};
|
||||
|
||||
const hasAccess = () => {
|
||||
switch (requiredPlan) {
|
||||
case "any":
|
||||
return sessionSubscriptions.hasPaidFeatures();
|
||||
case "plus":
|
||||
return (
|
||||
sessionSubscriptions.hasActivePlusSubscription() ||
|
||||
sessionSubscriptions.hasActiveProSubscription() ||
|
||||
sessionSubscriptions.hasActiveEliteSubscription()
|
||||
);
|
||||
case "pro":
|
||||
return (
|
||||
sessionSubscriptions.hasActiveProSubscription() ||
|
||||
sessionSubscriptions.hasActiveEliteSubscription()
|
||||
);
|
||||
case "elite":
|
||||
return sessionSubscriptions.hasActiveEliteSubscription();
|
||||
default:
|
||||
return sessionSubscriptions.hasPaidFeatures();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{hasAccess() ? (
|
||||
children
|
||||
) : (
|
||||
<div className="relative overflow-hidden rounded-lg bg-ui-controls px-3">
|
||||
<div className="pointer-events-none pb-3 pt-10">{children}</div>
|
||||
|
||||
<div className="absolute left-0 top-0 z-10 flex h-full w-full rounded-lg border border-brand-primary/40 bg-brand-secondary/60 pl-3 text-white/90">
|
||||
<div className="mt-2 flex justify-center">
|
||||
<div>
|
||||
<FontAwesomeIcon icon={faLock} className="me-2 text-sm" />
|
||||
|
||||
<span className="text-sm font-medium">
|
||||
{plural
|
||||
? "These features require "
|
||||
: "This feature requires "}
|
||||
<Link
|
||||
to="/pricing"
|
||||
className="text-brand-primary brightness-125 transition-all hover:brightness-150">
|
||||
{getPlanMessage(requiredPlan)}
|
||||
</Link>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export { default } from "./PremiumLock";
|
||||
@@ -8,6 +8,7 @@ import { toEngineActions } from "~/pages/PageEnigma/Queue/toEngineActions";
|
||||
import { Switch } from "@headlessui/react";
|
||||
import { useState } from "react";
|
||||
import { GenerationOptions } from "~/pages/PageEnigma/models/generationOptions";
|
||||
import PremiumLock from "~/components/PremiumLock";
|
||||
export function StyleButtons() {
|
||||
useSignals();
|
||||
|
||||
@@ -72,46 +73,50 @@ export function StyleButtons() {
|
||||
)}
|
||||
</div>
|
||||
<div className="w-full">
|
||||
<Switch.Group>
|
||||
<div className="mt-1 flex gap-6">
|
||||
<div className="flex items-center">
|
||||
<Switch.Label className="mr-3 text-sm font-medium">
|
||||
Upscale
|
||||
</Switch.Label>
|
||||
<Switch
|
||||
checked={upscale}
|
||||
onChange={setUpscale}
|
||||
className={`${
|
||||
upscale ? "bg-brand-primary" : "bg-gray-500 hover:bg-gray-400"
|
||||
} relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-0 focus:ring-offset-0`}>
|
||||
<span
|
||||
<PremiumLock requiredPlan="any" plural={true}>
|
||||
<Switch.Group>
|
||||
<div className="mt-1 flex gap-6">
|
||||
<div className="flex items-center">
|
||||
<Switch.Label className="mr-3 text-sm font-medium">
|
||||
Upscale
|
||||
</Switch.Label>
|
||||
<Switch
|
||||
checked={upscale}
|
||||
onChange={setUpscale}
|
||||
className={`${
|
||||
upscale ? "translate-x-6" : "translate-x-1"
|
||||
} inline-block h-4 w-4 transform rounded-full bg-white transition-transform`}
|
||||
/>
|
||||
</Switch>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<Switch.Label className="mr-3 text-sm font-medium">
|
||||
Face Detail
|
||||
</Switch.Label>
|
||||
<Switch
|
||||
checked={faceDetail}
|
||||
onChange={setFaceDetail}
|
||||
className={`${
|
||||
faceDetail
|
||||
? "bg-brand-primary"
|
||||
: "bg-gray-500 hover:bg-gray-400"
|
||||
} focus:ring-indigo-500 relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-0 focus:ring-offset-0`}>
|
||||
<span
|
||||
upscale
|
||||
? "bg-brand-primary"
|
||||
: "bg-gray-500 hover:bg-gray-400"
|
||||
} relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-0 focus:ring-offset-0`}>
|
||||
<span
|
||||
className={`${
|
||||
upscale ? "translate-x-6" : "translate-x-1"
|
||||
} inline-block h-4 w-4 transform rounded-full bg-white transition-transform`}
|
||||
/>
|
||||
</Switch>
|
||||
</div>
|
||||
<div className="flex items-center">
|
||||
<Switch.Label className="mr-3 text-sm font-medium">
|
||||
Face Detail
|
||||
</Switch.Label>
|
||||
<Switch
|
||||
checked={faceDetail}
|
||||
onChange={setFaceDetail}
|
||||
className={`${
|
||||
faceDetail ? "translate-x-6" : "translate-x-1"
|
||||
} inline-block h-4 w-4 transform rounded-full bg-white transition-transform`}
|
||||
/>
|
||||
</Switch>
|
||||
faceDetail
|
||||
? "bg-brand-primary"
|
||||
: "bg-gray-500 hover:bg-gray-400"
|
||||
} focus:ring-indigo-500 relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-0 focus:ring-offset-0`}>
|
||||
<span
|
||||
className={`${
|
||||
faceDetail ? "translate-x-6" : "translate-x-1"
|
||||
} inline-block h-4 w-4 transform rounded-full bg-white transition-transform`}
|
||||
/>
|
||||
</Switch>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Switch.Group>
|
||||
</Switch.Group>
|
||||
</PremiumLock>
|
||||
|
||||
<hr className="my-3 opacity-10" />
|
||||
|
||||
|
||||
Reference in new issue
Block a user