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,
|
useRef,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { generateSchedule, generateReminderSchedule } from './utils/schedule';
|
import { generateSchedule, generateReminderSchedule } from './utils/schedule';
|
||||||
|
import { getAppConfig } from './utils/env';
|
||||||
import {
|
import {
|
||||||
Medication,
|
Medication,
|
||||||
Dose,
|
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'
|
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' />
|
<MenuIcon className='w-4 h-4' aria-hidden='true' />
|
||||||
<span>{import.meta.env.VITE_APP_NAME || 'Meds'}</span>
|
<span>{getAppConfig().name}</span>
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={onManageReminders}
|
onClick={onManageReminders}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { EmailVerificationToken } from '../auth.types';
|
import { EmailVerificationToken } from '../auth.types';
|
||||||
import { unifiedConfig } from '../../../config/unified.config';
|
import { getAppConfig } from '../../../config/unified.config';
|
||||||
|
|
||||||
export const verificationEmailTemplate = (token: EmailVerificationToken) => {
|
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 `
|
return `
|
||||||
<html>
|
<html>
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
} from '../../types';
|
} from '../../types';
|
||||||
import { AccountStatus } from '../auth/auth.constants';
|
import { AccountStatus } from '../auth/auth.constants';
|
||||||
import { DatabaseStrategy, DatabaseError } from './types';
|
import { DatabaseStrategy, DatabaseError } from './types';
|
||||||
import { databaseConfig } from '../../config/unified.config';
|
import { getDatabaseConfig } from '../../config/unified.config';
|
||||||
import { logger } from '../logging';
|
import { logger } from '../logging';
|
||||||
|
|
||||||
export class ProductionDatabaseStrategy implements DatabaseStrategy {
|
export class ProductionDatabaseStrategy implements DatabaseStrategy {
|
||||||
@@ -19,7 +19,7 @@ export class ProductionDatabaseStrategy implements DatabaseStrategy {
|
|||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
// Get CouchDB configuration from unified config
|
// Get CouchDB configuration from unified config
|
||||||
const dbConfig = databaseConfig;
|
const dbConfig = getDatabaseConfig();
|
||||||
|
|
||||||
this.baseUrl = dbConfig.url;
|
this.baseUrl = dbConfig.url;
|
||||||
this.auth = btoa(`${dbConfig.username}:${dbConfig.password}`);
|
this.auth = btoa(`${dbConfig.username}:${dbConfig.password}`);
|
||||||
@@ -28,9 +28,6 @@ export class ProductionDatabaseStrategy implements DatabaseStrategy {
|
|||||||
url: dbConfig.url,
|
url: dbConfig.url,
|
||||||
username: dbConfig.username,
|
username: dbConfig.username,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Initialize databases
|
|
||||||
this.initializeDatabases();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initializeDatabases(): Promise<void> {
|
private async initializeDatabases(): Promise<void> {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { getMailgunConfig, type MailgunConfig } from './mailgun.config';
|
import { getMailgunConfig, type MailgunConfig } from './mailgun.config';
|
||||||
import { unifiedConfig } from '../config/unified.config';
|
import { getAppConfig } from '../config/unified.config';
|
||||||
|
|
||||||
interface EmailTemplate {
|
interface EmailTemplate {
|
||||||
subject: string;
|
subject: string;
|
||||||
@@ -139,13 +139,13 @@ export class MailgunService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async sendVerificationEmail(email: string, token: string): Promise<boolean> {
|
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);
|
const template = this.getVerificationEmailTemplate(verificationUrl);
|
||||||
return this.sendEmail(email, template);
|
return this.sendEmail(email, template);
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendPasswordResetEmail(email: string, token: string): Promise<boolean> {
|
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);
|
const template = this.getPasswordResetEmailTemplate(resetUrl);
|
||||||
return this.sendEmail(email, template);
|
return this.sendEmail(email, template);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user