feat: Introduce app feature flags
This commit refactors the application settings to include a new `AppFeatures` interface. This allows for granular control over which features are enabled for the application. The `AppFeatures` object includes boolean flags for: - `multiCondo`: Enables or disables the multi-condominium management feature. - `tickets`: Placeholder for future ticket system integration. - `payPal`: Enables or disables PayPal payment gateway integration. - `notices`: Enables or disables the display and management of notices. These flags are now fetched and stored in the application state, influencing UI elements and logic across various pages to conditionally render features based on their enabled status. For example, the multi-condo selection in `Layout.tsx` and the notice display in `FamilyList.tsx` are now gated by these feature flags. The `FamilyDetail.tsx` page also uses the `payPal` flag to conditionally enable the PayPal payment option. The `SettingsPage.tsx` has been updated to include a new 'features' tab for managing these flags.
This commit is contained in:
@@ -161,6 +161,8 @@ export const FamilyDetail: React.FC = () => {
|
||||
handlePaymentSuccess();
|
||||
};
|
||||
|
||||
const isPayPalEnabled = condo?.paypalClientId && settings?.features.payPal;
|
||||
|
||||
if (loading) return <div className="p-8 text-center text-slate-500">Caricamento dettagli...</div>;
|
||||
if (!family) return <div className="p-8 text-center text-red-500">Famiglia non trovata.</div>;
|
||||
|
||||
@@ -202,7 +204,7 @@ export const FamilyDetail: React.FC = () => {
|
||||
|
||||
<button
|
||||
onClick={() => {
|
||||
setPaymentMethod(condo?.paypalClientId ? 'paypal' : 'manual');
|
||||
setPaymentMethod(isPayPalEnabled ? 'paypal' : 'manual');
|
||||
setShowAddModal(true);
|
||||
}}
|
||||
className="flex-1 md:flex-none flex items-center justify-center gap-2 bg-blue-600 hover:bg-blue-700 text-white px-4 py-2.5 rounded-lg shadow-sm font-medium transition-all active:scale-95 whitespace-nowrap"
|
||||
@@ -305,7 +307,7 @@ export const FamilyDetail: React.FC = () => {
|
||||
<button
|
||||
onClick={() => {
|
||||
setNewPaymentMonth(month.monthIndex + 1);
|
||||
setPaymentMethod(condo?.paypalClientId ? 'paypal' : 'manual');
|
||||
setPaymentMethod(isPayPalEnabled ? 'paypal' : 'manual');
|
||||
setShowAddModal(true);
|
||||
}}
|
||||
className="ml-auto text-blue-600 hover:text-blue-800 text-xs font-bold uppercase tracking-wide px-2 py-1 rounded hover:bg-blue-50 transition-colors"
|
||||
@@ -376,7 +378,7 @@ export const FamilyDetail: React.FC = () => {
|
||||
|
||||
<div className="p-6">
|
||||
{/* Payment Method Switcher */}
|
||||
{condo?.paypalClientId && (
|
||||
{isPayPalEnabled && (
|
||||
<div className="flex bg-slate-100 rounded-lg p-1 mb-6">
|
||||
<button
|
||||
onClick={() => setPaymentMethod('manual')}
|
||||
@@ -452,8 +454,8 @@ export const FamilyDetail: React.FC = () => {
|
||||
</div>
|
||||
) : (
|
||||
<div className="min-h-[150px] flex items-center justify-center">
|
||||
{condo?.paypalClientId && (
|
||||
<PayPalScriptProvider options={{ clientId: condo.paypalClientId, currency: "EUR" }}>
|
||||
{isPayPalEnabled && (
|
||||
<PayPalScriptProvider options={{ clientId: condo.paypalClientId!, currency: "EUR" }}>
|
||||
<PayPalButtons
|
||||
style={{ layout: "vertical" }}
|
||||
createOrder={(data, actions) => {
|
||||
|
||||
Reference in New Issue
Block a user