refactor: update application code to use unified configuration
- Update App.tsx to use getAppConfig() instead of import.meta.env - Update email templates to use getAppConfig() for base URL - Update database strategy to use getDatabaseConfig() function - Update mailgun service to use getter functions - Remove direct unified config imports in favor of functions - Ensure consistent configuration access throughout codebase
This commit is contained in:
3
App.tsx
3
App.tsx
@@ -6,6 +6,7 @@ import React, {
|
||||
useRef,
|
||||
} from 'react';
|
||||
import { generateSchedule, generateReminderSchedule } from './utils/schedule';
|
||||
import { getAppConfig } from './utils/env';
|
||||
import {
|
||||
Medication,
|
||||
Dose,
|
||||
@@ -115,7 +116,7 @@ const Header: React.FC<{
|
||||
className='hidden sm:flex items-center space-x-2 px-4 py-2 text-sm font-medium text-slate-700 bg-slate-100 rounded-lg hover:bg-slate-200 transition-colors dark:bg-slate-700 dark:text-slate-200 dark:hover:bg-slate-600'
|
||||
>
|
||||
<MenuIcon className='w-4 h-4' aria-hidden='true' />
|
||||
<span>{import.meta.env.VITE_APP_NAME || 'Meds'}</span>
|
||||
<span>{getAppConfig().name}</span>
|
||||
</button>
|
||||
<button
|
||||
onClick={onManageReminders}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { EmailVerificationToken } from '../auth.types';
|
||||
import { unifiedConfig } from '../../../config/unified.config';
|
||||
import { getAppConfig } from '../../../config/unified.config';
|
||||
|
||||
export const verificationEmailTemplate = (token: EmailVerificationToken) => {
|
||||
const verificationLink = `${unifiedConfig.app.baseUrl}/verify-email?token=${token.token}`;
|
||||
const verificationLink = `${getAppConfig().baseUrl}/verify-email?token=${token.token}`;
|
||||
|
||||
return `
|
||||
<html>
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
} from '../../types';
|
||||
import { AccountStatus } from '../auth/auth.constants';
|
||||
import { DatabaseStrategy, DatabaseError } from './types';
|
||||
import { databaseConfig } from '../../config/unified.config';
|
||||
import { getDatabaseConfig } from '../../config/unified.config';
|
||||
import { logger } from '../logging';
|
||||
|
||||
export class ProductionDatabaseStrategy implements DatabaseStrategy {
|
||||
@@ -19,7 +19,7 @@ export class ProductionDatabaseStrategy implements DatabaseStrategy {
|
||||
|
||||
constructor() {
|
||||
// Get CouchDB configuration from unified config
|
||||
const dbConfig = databaseConfig;
|
||||
const dbConfig = getDatabaseConfig();
|
||||
|
||||
this.baseUrl = dbConfig.url;
|
||||
this.auth = btoa(`${dbConfig.username}:${dbConfig.password}`);
|
||||
@@ -28,9 +28,6 @@ export class ProductionDatabaseStrategy implements DatabaseStrategy {
|
||||
url: dbConfig.url,
|
||||
username: dbConfig.username,
|
||||
});
|
||||
|
||||
// Initialize databases
|
||||
this.initializeDatabases();
|
||||
}
|
||||
|
||||
private async initializeDatabases(): Promise<void> {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { getMailgunConfig, type MailgunConfig } from './mailgun.config';
|
||||
import { unifiedConfig } from '../config/unified.config';
|
||||
import { getAppConfig } from '../config/unified.config';
|
||||
|
||||
interface EmailTemplate {
|
||||
subject: string;
|
||||
@@ -139,13 +139,13 @@ export class MailgunService {
|
||||
}
|
||||
|
||||
async sendVerificationEmail(email: string, token: string): Promise<boolean> {
|
||||
const verificationUrl = `${unifiedConfig.app.baseUrl}/verify-email?token=${token}`;
|
||||
const verificationUrl = `${getAppConfig().baseUrl}/verify-email?token=${token}`;
|
||||
const template = this.getVerificationEmailTemplate(verificationUrl);
|
||||
return this.sendEmail(email, template);
|
||||
}
|
||||
|
||||
async sendPasswordResetEmail(email: string, token: string): Promise<boolean> {
|
||||
const resetUrl = `${unifiedConfig.app.baseUrl}/reset-password?token=${token}`;
|
||||
const resetUrl = `${getAppConfig().baseUrl}/reset-password?token=${token}`;
|
||||
const template = this.getPasswordResetEmailTemplate(resetUrl);
|
||||
return this.sendEmail(email, template);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user