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:
@@ -144,14 +144,21 @@ app.get('/api/settings', authenticateToken, async (req, res) => {
|
||||
try {
|
||||
const [rows] = await pool.query('SELECT * FROM settings WHERE id = 1');
|
||||
if (rows.length > 0) {
|
||||
res.json({ currentYear: rows[0].current_year, smtpConfig: rows[0].smtp_config || {} });
|
||||
res.json({
|
||||
currentYear: rows[0].current_year,
|
||||
smtpConfig: rows[0].smtp_config || {},
|
||||
features: rows[0].features || { multiCondo: true, tickets: true, payPal: true, notices: true }
|
||||
});
|
||||
} else { res.status(404).json({ message: 'Settings not found' }); }
|
||||
} catch (e) { res.status(500).json({ error: e.message }); }
|
||||
});
|
||||
app.put('/api/settings', authenticateToken, requireAdmin, async (req, res) => {
|
||||
const { currentYear, smtpConfig } = req.body;
|
||||
const { currentYear, smtpConfig, features } = req.body;
|
||||
try {
|
||||
await pool.query('UPDATE settings SET current_year = ?, smtp_config = ? WHERE id = 1', [currentYear, JSON.stringify(smtpConfig)]);
|
||||
await pool.query(
|
||||
'UPDATE settings SET current_year = ?, smtp_config = ?, features = ? WHERE id = 1',
|
||||
[currentYear, JSON.stringify(smtpConfig), JSON.stringify(features)]
|
||||
);
|
||||
res.json({ success: true });
|
||||
} catch (e) { res.status(500).json({ error: e.message }); }
|
||||
});
|
||||
@@ -664,4 +671,4 @@ initDb().then(() => {
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server running on port ${PORT}`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user