Spaces:
Running
Running
Claude Opus 5.5
feat: new landing, template system, auto-layout, Free/Plus plans; remove AI and hide habits
0dcbaee Download src/pages/SubscriptionPage.jsx from DanilDrotik/FlowWeb: direct link, hf CLI and curl.
- Browser
- Download file 10.2 kB
-
https://huggingface.co/spaces/DanilDrotik/FlowWeb/resolve/main/src/pages/SubscriptionPage.jsx
- Command line
-
hf download hf://spaces/DanilDrotik/FlowWeb/src/pages/SubscriptionPage.jsx
-
curl -L -o SubscriptionPage.jsx https://huggingface.co/spaces/DanilDrotik/FlowWeb/resolve/main/src/pages/SubscriptionPage.jsx
10.2 kB
| import React from 'react'; | |
| import { motion, AnimatePresence } from 'framer-motion'; | |
| import { useTranslation } from 'react-i18next'; | |
| import axios from 'axios'; | |
| import { Check, Zap, ArrowRight, Layout, Network, Users, LayoutTemplate, Infinity as InfinityIcon } from 'lucide-react'; | |
| import Sidebar from '../components/Sidebar'; | |
| import { useAuth } from '../context/AuthContext'; | |
| import { FREE_LIMITS, PLAN_FREE, PLAN_PLUS, PLUS_PRICE_USD, normalizePlan } from '../config/plans'; | |
| const PlanCard = ({ title, price, description, features, highlighted, buttonText, isCurrentPlan, onClick, loading, delay }) => { | |
| const { t } = useTranslation(); | |
| return ( | |
| <motion.div | |
| initial={{ opacity: 0, y: 30 }} | |
| animate={{ opacity: 1, y: 0 }} | |
| transition={{ delay, type: 'spring', stiffness: 120, damping: 18 }} | |
| whileHover={isCurrentPlan ? {} : { y: -8 }} | |
| className={`relative bg-surface-container-lowest p-10 rough-border flex flex-col gap-8 h-full ${ | |
| highlighted ? 'shadow-[12px_12px_0px_0px_var(--color-primary)] border-secondary' : 'rough-shadow' | |
| }`} | |
| > | |
| {highlighted && ( | |
| <div className="absolute -top-5 left-1/2 -translate-x-1/2 bg-secondary text-primary px-6 py-2 rough-border font-bold text-sm uppercase tracking-widest whitespace-nowrap"> | |
| {t('plans.no_limits', 'No limits')} | |
| </div> | |
| )} | |
| <div className="text-center border-b-2 border-primary/10 pb-8"> | |
| <h3 className="text-5xl font-display-lg text-primary mb-2">{title}</h3> | |
| <div className="flex items-center justify-center gap-1"> | |
| <span className="text-2xl font-display-lg text-secondary">$</span> | |
| <span className="text-6xl font-display-lg text-primary">{price}</span> | |
| <span className="text-sm font-bold text-on-surface-variant uppercase tracking-widest mt-4">{t('subscription.per_month')}</span> | |
| </div> | |
| <p className="mt-4 text-sm text-on-surface-variant font-medium">{description}</p> | |
| </div> | |
| <ul className="flex flex-col gap-4 flex-grow"> | |
| {features.map((f, i) => ( | |
| <li key={i} className="flex items-start gap-3"> | |
| <Check size={18} className="text-secondary mt-1 flex-shrink-0" /> | |
| <span className="text-sm font-bold text-primary">{f}</span> | |
| </li> | |
| ))} | |
| </ul> | |
| <motion.button | |
| whileHover={isCurrentPlan ? {} : { scale: 1.02 }} | |
| whileTap={isCurrentPlan ? {} : { scale: 0.98 }} | |
| onClick={isCurrentPlan ? undefined : onClick} | |
| disabled={isCurrentPlan || loading} | |
| className={`w-full py-4 text-xl font-bold flex items-center justify-center gap-2 rough-border transition-all ${ | |
| isCurrentPlan | |
| ? 'bg-surface-container-high text-on-surface-variant/50 border-primary/20 cursor-default' | |
| : highlighted | |
| ? 'bg-primary text-on-primary hover:bg-primary/95 cursor-pointer' | |
| : 'bg-surface-container-lowest text-primary border-primary hover:bg-primary/5 cursor-pointer' | |
| }`} | |
| > | |
| <span>{isCurrentPlan ? t('subscription.current_plan', 'Current plan') : loading ? t('subscription.upgrading', 'Switching...') : buttonText}</span> | |
| {!isCurrentPlan && !loading && <ArrowRight size={20} />} | |
| </motion.button> | |
| </motion.div> | |
| ); | |
| }; | |
| const SubscriptionPage = () => { | |
| const { t } = useTranslation(); | |
| const { user, updateUser } = useAuth(); | |
| const [loadingPlan, setLoadingPlan] = React.useState(null); | |
| const [notification, setNotification] = React.useState(null); | |
| const notify = (type, message) => { | |
| setNotification({ type, message }); | |
| setTimeout(() => setNotification(null), 4500); | |
| }; | |
| const handleChangePlan = async (plan) => { | |
| if (!user) return; | |
| setLoadingPlan(plan); | |
| try { | |
| const API_URL = import.meta.env.VITE_API_URL; | |
| const res = await axios.post(`${API_URL}/payments/change-tier`, { tier: plan }); | |
| updateUser(res.data); | |
| notify('success', t('plans.switched', { plan, defaultValue: `Your plan is now ${plan}.` })); | |
| } catch (err) { | |
| if (err.response?.status === 402) { | |
| notify('error', t('plans.payments_soon', 'Online payments are not connected yet. Plus will be available soon.')); | |
| } else { | |
| notify('error', err.response?.data?.message || t('plans.switch_failed', 'Could not change the plan. Please try again.')); | |
| } | |
| } finally { | |
| setLoadingPlan(null); | |
| } | |
| }; | |
| const currentPlan = normalizePlan(user?.subscriptionTier); | |
| const plans = [ | |
| { | |
| key: PLAN_FREE, | |
| title: 'Free', | |
| price: '0', | |
| description: t('plans.free_desc', 'Everything you need to plan on your own.'), | |
| buttonText: t('plans.free_btn', 'Switch to Free'), | |
| features: [ | |
| t('plans.feat_boards', { count: FREE_LIMITS.boards, defaultValue: `Up to ${FREE_LIMITS.boards} boards` }), | |
| t('plans.feat_nodes', { count: FREE_LIMITS.nodesPerBoard, defaultValue: `Up to ${FREE_LIMITS.nodesPerBoard} nodes per board` }), | |
| t('plans.feat_guests', { count: FREE_LIMITS.guestsPerBoard, defaultValue: `Up to ${FREE_LIMITS.guestsPerBoard} guests per board` }), | |
| t('plans.feat_templates', { count: FREE_LIMITS.templates, defaultValue: `${FREE_LIMITS.templates} saved templates` }), | |
| t('plans.feat_core', 'All node types, auto-layout, PNG/JSON export'), | |
| ], | |
| }, | |
| { | |
| key: PLAN_PLUS, | |
| title: 'Plus', | |
| price: String(PLUS_PRICE_USD), | |
| highlighted: true, | |
| description: t('plans.plus_desc', 'For big plans and teams. No caps on anything.'), | |
| buttonText: t('plans.plus_btn', 'Get Plus'), | |
| features: [ | |
| t('plans.feat_unlimited_boards', 'Unlimited boards'), | |
| t('plans.feat_unlimited_nodes', 'Unlimited nodes'), | |
| t('plans.feat_unlimited_guests', 'Unlimited collaborators'), | |
| t('plans.feat_unlimited_templates', 'Unlimited saved templates'), | |
| t('plans.feat_everything_free', 'Everything in Free'), | |
| ], | |
| }, | |
| ]; | |
| const rows = [ | |
| { icon: Layout, label: t('plans.row_boards', 'Boards'), free: FREE_LIMITS.boards }, | |
| { icon: Network, label: t('plans.row_nodes', 'Nodes per board'), free: FREE_LIMITS.nodesPerBoard }, | |
| { icon: Users, label: t('plans.row_guests', 'Guests per board'), free: FREE_LIMITS.guestsPerBoard }, | |
| { icon: LayoutTemplate, label: t('plans.row_templates', 'Saved templates'), free: FREE_LIMITS.templates }, | |
| ]; | |
| return ( | |
| <div className="flex h-screen bg-background overflow-hidden"> | |
| <Sidebar /> | |
| <main className="flex-grow flex flex-col relative overflow-y-auto graph-paper-bg scrollbar-hide"> | |
| <AnimatePresence> | |
| {notification && ( | |
| <motion.div | |
| initial={{ opacity: 0, y: -50 }} | |
| animate={{ opacity: 1, y: 0 }} | |
| exit={{ opacity: 0, y: -50 }} | |
| className={`fixed top-6 left-1/2 -translate-x-1/2 px-8 py-4 z-50 rough-border shadow-2xl font-bold text-lg text-white max-w-[90vw] text-center ${ | |
| notification.type === 'success' ? 'bg-primary' : 'bg-error' | |
| }`} | |
| > | |
| {notification.message} | |
| </motion.div> | |
| )} | |
| </AnimatePresence> | |
| <section className="p-8 md:p-16 flex flex-col gap-12 max-w-5xl mx-auto w-full relative z-10 pb-16"> | |
| <div className="text-center flex flex-col items-center gap-6"> | |
| <motion.div | |
| initial={{ scale: 0, rotate: -30 }} | |
| animate={{ scale: 1, rotate: 0 }} | |
| transition={{ type: 'spring', stiffness: 200, damping: 12 }} | |
| className="w-24 h-24 bg-secondary rounded-full flex items-center justify-center border-4 border-primary shadow-xl" | |
| > | |
| <Zap size={48} className="text-primary" /> | |
| </motion.div> | |
| <h1 className="text-6xl md:text-7xl font-display-lg text-primary leading-tight max-w-3xl"> | |
| {t('plans.title_p1', 'Two plans. ')} | |
| <span className="highlighter-bg">{t('plans.title_highlight', 'No fine print.')}</span> | |
| </h1> | |
| <p className="font-accent-note text-3xl text-secondary -rotate-1 max-w-xl"> | |
| {t('plans.subtitle', 'Free has small creation limits. Plus has none.')} | |
| </p> | |
| </div> | |
| <div className="grid grid-cols-1 md:grid-cols-2 gap-10 items-stretch"> | |
| {plans.map((plan, i) => ( | |
| <PlanCard | |
| key={plan.key} | |
| {...plan} | |
| delay={0.1 + i * 0.1} | |
| isCurrentPlan={currentPlan === plan.key} | |
| onClick={() => handleChangePlan(plan.key)} | |
| loading={loadingPlan === plan.key} | |
| /> | |
| ))} | |
| </div> | |
| <div className="w-full overflow-x-auto"> | |
| <table className="w-full text-sm border-2 border-primary/15 rough-border"> | |
| <thead> | |
| <tr className="border-b-2 border-primary/15"> | |
| <th className="text-left p-4 font-bold text-on-surface-variant uppercase tracking-widest text-xs">{t('subscription.compare.feature', 'Feature')}</th> | |
| <th className="p-4 font-bold text-primary text-center">Free</th> | |
| <th className="p-4 font-bold text-secondary text-center bg-secondary/5">Plus</th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| {rows.map((row, i) => ( | |
| <tr key={i} className="border-b border-primary/10"> | |
| <td className="p-4 font-semibold text-on-surface-variant flex items-center gap-2"> | |
| <row.icon size={16} className="text-secondary flex-shrink-0" /> | |
| {row.label} | |
| </td> | |
| <td className="p-4 text-center font-bold text-primary">{row.free}</td> | |
| <td className="p-4 text-center font-bold bg-secondary/5"> | |
| <InfinityIcon size={20} className="text-secondary mx-auto" /> | |
| </td> | |
| </tr> | |
| ))} | |
| </tbody> | |
| </table> | |
| </div> | |
| </section> | |
| </main> | |
| </div> | |
| ); | |
| }; | |
| export default SubscriptionPage; | |