From 5006b1abad8162e2efb64136ea6f3e7239ffc6c0 Mon Sep 17 00:00:00 2001 From: swve Date: Wed, 18 Dec 2024 01:11:32 +0100 Subject: [PATCH] fix: switching issues in payments dashboard --- .../dash/payments/[subpage]/page.tsx | 91 +++++++++---------- .../Payments/PaymentsConfigurationPage.tsx | 2 +- .../Pages/Payments/PaymentsCustomersPage.tsx | 2 +- 3 files changed, 43 insertions(+), 52 deletions(-) diff --git a/apps/web/app/orgs/[orgslug]/dash/payments/[subpage]/page.tsx b/apps/web/app/orgs/[orgslug]/dash/payments/[subpage]/page.tsx index 173ececd..7d52fd43 100644 --- a/apps/web/app/orgs/[orgslug]/dash/payments/[subpage]/page.tsx +++ b/apps/web/app/orgs/[orgslug]/dash/payments/[subpage]/page.tsx @@ -1,10 +1,10 @@ 'use client' -import React, { useState, useEffect } from 'react' +import React from 'react' import { motion } from 'framer-motion' import BreadCrumbs from '@components/Dashboard/Misc/BreadCrumbs' import Link from 'next/link' import { getUriWithOrg } from '@services/config/config' -import { CreditCard, Settings, Repeat, BookOpen, Users, DollarSign, Gem } from 'lucide-react' +import { Settings, Users, Gem } from 'lucide-react' import { useLHSession } from '@components/Contexts/LHSessionContext' import { useOrg } from '@components/Contexts/OrgContext' import PaymentsConfigurationPage from '@components/Dashboard/Pages/Payments/PaymentsConfigurationPage' @@ -20,18 +20,37 @@ export type PaymentsParams = { function PaymentsPage({ params }: { params: PaymentsParams }) { const session = useLHSession() as any const org = useOrg() as any - const [selectedSubPage, setSelectedSubPage] = useState(params.subpage || 'general') - const [H1Label, setH1Label] = useState('') - const [H2Label, setH2Label] = useState('') + const subpage = params.subpage || 'customers' const isPaymentsEnabled = useFeatureFlag({ path: ['features', 'payments', 'enabled'], defaultValue: false }) - useEffect(() => { - handleLabels() - }, [selectedSubPage]) + const getPageTitle = () => { + switch (subpage) { + case 'customers': + return { + h1: 'Customers', + h2: 'View and manage your customer information' + } + case 'paid-products': + return { + h1: 'Paid Products', + h2: 'Manage your paid products and pricing' + } + case 'configuration': + return { + h1: 'Payment Configuration', + h2: 'Set up and manage your payment gateway' + } + default: + return { + h1: 'Payments', + h2: 'Overview of your payment settings and transactions' + } + } + } if (!isPaymentsEnabled) { return ( @@ -45,66 +64,41 @@ function PaymentsPage({ params }: { params: PaymentsParams }) { ) } - function handleLabels() { - if (selectedSubPage === 'general') { - setH1Label('Payments') - setH2Label('Overview of your payment settings and transactions') - } - if (selectedSubPage === 'configuration') { - setH1Label('Payment Configuration') - setH2Label('Set up and manage your payment gateway') - } - if (selectedSubPage === 'subscriptions') { - setH1Label('Subscriptions') - setH2Label('Manage your subscription plans') - } - if (selectedSubPage === 'paid-products') { - setH1Label('Paid Products') - setH2Label('Manage your paid products and pricing') - } - if (selectedSubPage === 'customers') { - setH1Label('Customers') - setH2Label('View and manage your customer information') - } - } + const { h1, h2 } = getPageTitle() return (
-
+
-
+
- {H1Label} + {h1}
- {H2Label}{' '} + {h2}
-
+
} label="Customers" - isActive={selectedSubPage === 'customers'} - onClick={() => setSelectedSubPage('customers')} + isActive={subpage === 'customers'} /> } label="Products & Subscriptions" - isActive={selectedSubPage === 'paid-products'} - onClick={() => setSelectedSubPage('paid-products')} + isActive={subpage === 'paid-products'} /> } label="Configuration" - isActive={selectedSubPage === 'configuration'} - onClick={() => setSelectedSubPage('configuration')} + isActive={subpage === 'configuration'} /> -
@@ -115,21 +109,18 @@ function PaymentsPage({ params }: { params: PaymentsParams }) { transition={{ duration: 0.1, type: 'spring', stiffness: 80 }} className="flex-1 overflow-y-auto" > - {selectedSubPage === 'general' &&
General
} - {selectedSubPage === 'configuration' && } - {selectedSubPage === 'paid-products' && } - {selectedSubPage === 'customers' && } + {subpage === 'configuration' && } + {subpage === 'paid-products' && } + {subpage === 'customers' && }
) } -const TabLink = ({ href, icon, label, isActive, onClick }: { href: string, icon: React.ReactNode, label: string, isActive: boolean, onClick: () => void }) => ( +const TabLink = ({ href, icon, label, isActive }: { href: string, icon: React.ReactNode, label: string, isActive: boolean }) => (
{icon} diff --git a/apps/web/components/Dashboard/Pages/Payments/PaymentsConfigurationPage.tsx b/apps/web/components/Dashboard/Pages/Payments/PaymentsConfigurationPage.tsx index f2192d5e..dcfc74ad 100644 --- a/apps/web/components/Dashboard/Pages/Payments/PaymentsConfigurationPage.tsx +++ b/apps/web/components/Dashboard/Pages/Payments/PaymentsConfigurationPage.tsx @@ -83,7 +83,7 @@ const PaymentsConfigurationPage: React.FC = () => { return (
-
+

Payments Configuration

Manage your organization payments configuration

diff --git a/apps/web/components/Dashboard/Pages/Payments/PaymentsCustomersPage.tsx b/apps/web/components/Dashboard/Pages/Payments/PaymentsCustomersPage.tsx index e62d7e39..af6859a3 100644 --- a/apps/web/components/Dashboard/Pages/Payments/PaymentsCustomersPage.tsx +++ b/apps/web/components/Dashboard/Pages/Payments/PaymentsCustomersPage.tsx @@ -141,7 +141,7 @@ function PaymentsCustomersPage() { if (!customers) return
No customer data available
return ( -
+

Customers

View and manage your customer information