feat: Implement comprehensive error handling and production deployment pipeline
Some checks failed
ParentFlow CI/CD Pipeline / Backend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Frontend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Security Scanning (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-app/maternal-app-backend dockerfile:Dockerfile.production name:backend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-web dockerfile:Dockerfile.production name:frontend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Development (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled
Some checks failed
ParentFlow CI/CD Pipeline / Backend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Frontend Tests (push) Has been cancelled
ParentFlow CI/CD Pipeline / Security Scanning (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-app/maternal-app-backend dockerfile:Dockerfile.production name:backend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Build Docker Images (map[context:maternal-web dockerfile:Dockerfile.production name:frontend]) (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Development (push) Has been cancelled
ParentFlow CI/CD Pipeline / Deploy to Production (push) Has been cancelled
CI/CD Pipeline / Lint and Test (push) Has been cancelled
CI/CD Pipeline / E2E Tests (push) Has been cancelled
CI/CD Pipeline / Build Application (push) Has been cancelled
## Error Handling System - Add centralized error handling utilities (errorHandler.ts) - Create reusable error components (ErrorMessage, ErrorToast) - Implement multilingual error support (preserves backend error messages in 5 languages) - Update 15+ forms and components with consistent error handling - Auth forms: login, register, forgot-password - Family management: family page, join family dialog - Child management: child dialog - All tracking forms: feeding, sleep, diaper, medicine, growth, activity ## Production Build Fixes - Fix backend TypeScript errors: InviteCode.uses → InviteCode.useCount (5 instances) - Remove non-existent savedFamily variable from registration response - Fix admin panel TypeScript errors: SimpleMDE toolbar type, PieChart label type ## User Experience Improvements - Auto-uppercase invite code and share code inputs - Visual feedback for case conversion with helper text - Improved form validation with error codes ## CI/CD Pipeline - Create comprehensive production deployment checklist (PRODUCTION_DEPLOYMENT_CHECKLIST.md) - Add automated pre-deployment check script (pre-deploy-check.sh) - Validates frontend, backend, and admin panel builds - Checks git status, branch, and sync state - Verifies environment files and migrations - Add quick start deployment guide (DEPLOYMENT_QUICK_START.md) - Add production deployment automation template (deploy-production.sh) ## Cleanup - Remove outdated push notifications documentation files - Remove outdated PWA implementation plan 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -51,6 +51,8 @@ import { useDispatch, useSelector } from 'react-redux';
|
||||
import { fetchChildren, selectChild, selectSelectedChild, childrenSelectors } from '@/store/slices/childrenSlice';
|
||||
import { AppDispatch, RootState } from '@/store/store';
|
||||
import ChildSelector from '@/components/common/ChildSelector';
|
||||
import { useErrorMessage } from '@/components/common/ErrorMessage';
|
||||
import { formatErrorMessage } from '@/lib/utils/errorHandler';
|
||||
|
||||
interface ActivityData {
|
||||
activityType: string;
|
||||
@@ -83,7 +85,7 @@ function ActivityTrackPage() {
|
||||
const [recentActivities, setRecentActivities] = useState<Activity[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [activitiesLoading, setActivitiesLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const { error, showError, clearError, hasError } = useErrorMessage();
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
|
||||
// Delete confirmation dialog
|
||||
@@ -131,19 +133,19 @@ function ActivityTrackPage() {
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!selectedChild?.id) {
|
||||
setError('Please select a child');
|
||||
showError({ message: 'Please select a child', code: 'NO_CHILD_SELECTED' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Validation
|
||||
if (!activityType) {
|
||||
setError('Please select activity type');
|
||||
showError({ message: 'Please select activity type', code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
clearError();
|
||||
|
||||
const data: ActivityData = {
|
||||
activityType,
|
||||
@@ -167,7 +169,7 @@ function ActivityTrackPage() {
|
||||
await loadRecentActivities();
|
||||
} catch (err: any) {
|
||||
console.error('Failed to save activity:', err);
|
||||
setError(err.response?.data?.message || 'Failed to save activity');
|
||||
showError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -197,7 +199,7 @@ function ActivityTrackPage() {
|
||||
await loadRecentActivities();
|
||||
} catch (err: any) {
|
||||
console.error('Failed to delete activity:', err);
|
||||
setError(err.response?.data?.message || 'Failed to delete activity');
|
||||
showError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -306,9 +308,9 @@ function ActivityTrackPage() {
|
||||
/>
|
||||
</Box>
|
||||
|
||||
{error && (
|
||||
<Alert severity="error" sx={{ mb: 3 }} onClose={() => setError(null)}>
|
||||
{error}
|
||||
{hasError && (
|
||||
<Alert severity="error" sx={{ mb: 3 }} onClose={clearError}>
|
||||
{formatErrorMessage(error)}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
|
||||
@@ -48,6 +48,8 @@ import { childrenApi, Child } from '@/lib/api/children';
|
||||
import { motion } from 'framer-motion';
|
||||
import { useLocalizedDate } from '@/hooks/useLocalizedDate';
|
||||
import { useTranslation } from '@/hooks/useTranslation';
|
||||
import { useErrorMessage } from '@/components/common/ErrorMessage';
|
||||
import { formatErrorMessage } from '@/lib/utils/errorHandler';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { fetchChildren, selectChild, selectSelectedChild, childrenSelectors } from '@/store/slices/childrenSlice';
|
||||
import { AppDispatch, RootState } from '@/store/store';
|
||||
@@ -90,7 +92,7 @@ export default function DiaperTrackPage() {
|
||||
const [recentDiapers, setRecentDiapers] = useState<Activity[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [diapersLoading, setDiapersLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const { error, showError, clearError, hasError } = useErrorMessage();
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
|
||||
// Delete confirmation dialog
|
||||
@@ -215,24 +217,24 @@ export default function DiaperTrackPage() {
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!selectedChild?.id) {
|
||||
setError('Please select a child');
|
||||
showError({ message: 'Please select a child', code: 'NO_CHILD_SELECTED' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Validation
|
||||
if (!timestamp) {
|
||||
setError('Please enter timestamp');
|
||||
showError({ message: 'Please enter timestamp', code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (conditions.length === 0) {
|
||||
setError('Please select at least one condition');
|
||||
showError({ message: 'Please select at least one condition', code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
clearError();
|
||||
|
||||
const data: DiaperData = {
|
||||
diaperType,
|
||||
@@ -260,7 +262,7 @@ export default function DiaperTrackPage() {
|
||||
await loadRecentDiapers();
|
||||
} catch (err: any) {
|
||||
console.error('Failed to save diaper:', err);
|
||||
setError(err.response?.data?.message || 'Failed to save diaper change');
|
||||
showError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -292,7 +294,7 @@ export default function DiaperTrackPage() {
|
||||
await loadRecentDiapers();
|
||||
} catch (err: any) {
|
||||
console.error('Failed to delete diaper:', err);
|
||||
setError(err.response?.data?.message || 'Failed to delete diaper change');
|
||||
showError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -421,9 +423,9 @@ export default function DiaperTrackPage() {
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
{error && (
|
||||
<Alert severity="error" sx={{ mb: 3 }} onClose={() => setError(null)}>
|
||||
{error}
|
||||
{hasError && (
|
||||
<Alert severity="error" sx={{ mb: 3 }} onClose={clearError}>
|
||||
{formatErrorMessage(error)}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ import { motion } from 'framer-motion';
|
||||
import { useLocalizedDate } from '@/hooks/useLocalizedDate';
|
||||
import { useTranslation } from '@/hooks/useTranslation';
|
||||
import { UnitInput } from '@/components/forms/UnitInput';
|
||||
import { useErrorMessage } from '@/components/common/ErrorMessage';
|
||||
import { formatErrorMessage } from '@/lib/utils/errorHandler';
|
||||
import { convertVolume, getUnitSymbol } from '@/lib/utils/unitConversion';
|
||||
import { MeasurementSystem } from '@/hooks/useLocale';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
@@ -106,7 +108,7 @@ function FeedingTrackPage() {
|
||||
const [recentFeedings, setRecentFeedings] = useState<Activity[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [feedingsLoading, setFeedingsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const { error, showError, clearError, hasError } = useErrorMessage();
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
|
||||
// Delete confirmation dialog
|
||||
@@ -186,29 +188,29 @@ function FeedingTrackPage() {
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!selectedChild?.id) {
|
||||
setError(t('common.selectChild'));
|
||||
showError({ message: t('common.selectChild'), code: 'NO_CHILD_SELECTED' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Validation
|
||||
if (feedingType === 'breast' && duration === 0 && timerSeconds === 0) {
|
||||
setError(t('feeding.validation.durationRequired'));
|
||||
showError({ message: t('feeding.validation.durationRequired'), code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (feedingType === 'bottle' && !amount) {
|
||||
setError(t('feeding.validation.amountRequired'));
|
||||
showError({ message: t('feeding.validation.amountRequired'), code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (feedingType === 'solid' && !foodDescription) {
|
||||
setError(t('feeding.validation.foodRequired'));
|
||||
showError({ message: t('feeding.validation.foodRequired'), code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
clearError();
|
||||
|
||||
const data: FeedingData = {
|
||||
feedingType,
|
||||
@@ -241,7 +243,7 @@ function FeedingTrackPage() {
|
||||
await loadRecentFeedings();
|
||||
} catch (err: any) {
|
||||
console.error('Failed to save feeding:', err);
|
||||
setError(err.response?.data?.message || t('feeding.error.saveFailed'));
|
||||
showError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -276,7 +278,7 @@ function FeedingTrackPage() {
|
||||
await loadRecentFeedings();
|
||||
} catch (err: any) {
|
||||
console.error('Failed to delete feeding:', err);
|
||||
setError(err.response?.data?.message || t('feeding.error.deleteFailed'));
|
||||
showError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -398,9 +400,9 @@ function FeedingTrackPage() {
|
||||
/>
|
||||
</Box>
|
||||
|
||||
{error && (
|
||||
<Alert severity="error" sx={{ mb: 3 }} onClose={() => setError(null)}>
|
||||
{error}
|
||||
{hasError && (
|
||||
<Alert severity="error" sx={{ mb: 3 }} onClose={clearError}>
|
||||
{formatErrorMessage(error)}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ import { fetchChildren, selectChild, selectSelectedChild, childrenSelectors } fr
|
||||
import { AppDispatch, RootState } from '@/store/store';
|
||||
import ChildSelector from '@/components/common/ChildSelector';
|
||||
import { UnitInput } from '@/components/forms/UnitInput';
|
||||
import { useErrorMessage } from '@/components/common/ErrorMessage';
|
||||
import { formatErrorMessage } from '@/lib/utils/errorHandler';
|
||||
|
||||
interface GrowthData {
|
||||
weight?: number; // in kg
|
||||
@@ -84,7 +86,7 @@ function GrowthTrackPage() {
|
||||
const [recentGrowth, setRecentGrowth] = useState<Activity[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [growthLoading, setGrowthLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const { error, showError, clearError, hasError } = useErrorMessage();
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
|
||||
// Delete confirmation dialog
|
||||
@@ -132,31 +134,31 @@ function GrowthTrackPage() {
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!selectedChild?.id) {
|
||||
setError(t('common.selectChild'));
|
||||
showError({ message: t('common.selectChild'), code: 'NO_CHILD_SELECTED' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Validation
|
||||
if (measurementType === 'weight' && weight === 0) {
|
||||
setError('Please enter weight');
|
||||
showError({ message: 'Please enter weight', code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
if (measurementType === 'height' && height === 0) {
|
||||
setError('Please enter height');
|
||||
showError({ message: 'Please enter height', code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
if (measurementType === 'head' && headCircumference === 0) {
|
||||
setError('Please enter head circumference');
|
||||
showError({ message: 'Please enter head circumference', code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
if (measurementType === 'all' && (weight === 0 || height === 0 || headCircumference === 0)) {
|
||||
setError('Please enter all measurements');
|
||||
showError({ message: 'Please enter all measurements', code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
clearError();
|
||||
|
||||
const data: GrowthData = {
|
||||
measurementType,
|
||||
@@ -181,7 +183,7 @@ function GrowthTrackPage() {
|
||||
await loadRecentGrowth();
|
||||
} catch (err: any) {
|
||||
console.error('Failed to save growth:', err);
|
||||
setError(err.response?.data?.message || 'Failed to save growth measurement');
|
||||
showError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -212,7 +214,7 @@ function GrowthTrackPage() {
|
||||
await loadRecentGrowth();
|
||||
} catch (err: any) {
|
||||
console.error('Failed to delete growth:', err);
|
||||
setError(err.response?.data?.message || 'Failed to delete growth measurement');
|
||||
showError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -324,9 +326,9 @@ function GrowthTrackPage() {
|
||||
/>
|
||||
</Box>
|
||||
|
||||
{error && (
|
||||
<Alert severity="error" sx={{ mb: 3 }} onClose={() => setError(null)}>
|
||||
{error}
|
||||
{hasError && (
|
||||
<Alert severity="error" sx={{ mb: 3 }} onClose={clearError}>
|
||||
{formatErrorMessage(error)}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
|
||||
@@ -53,6 +53,8 @@ import { useTranslation } from '@/hooks/useTranslation';
|
||||
import { UnitInput } from '@/components/forms/UnitInput';
|
||||
import { convertVolume, convertTemperature } from '@/lib/utils/unitConversion';
|
||||
import { MeasurementSystem } from '@/hooks/useLocale';
|
||||
import { useErrorMessage } from '@/components/common/ErrorMessage';
|
||||
import { formatErrorMessage } from '@/lib/utils/errorHandler';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { fetchChildren, selectChild, selectSelectedChild, childrenSelectors } from '@/store/slices/childrenSlice';
|
||||
import { AppDispatch, RootState } from '@/store/store';
|
||||
@@ -121,7 +123,7 @@ function MedicalTrackPage() {
|
||||
const [recentActivities, setRecentActivities] = useState<Activity[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [activitiesLoading, setActivitiesLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const { error, showError, clearError, hasError } = useErrorMessage();
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
|
||||
// Delete confirmation dialog
|
||||
@@ -184,36 +186,36 @@ function MedicalTrackPage() {
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!selectedChild?.id) {
|
||||
setError(t('common.selectChild'));
|
||||
showError({ message: t('common.selectChild'), code: 'NO_CHILD_SELECTED' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Validation based on activity type
|
||||
if (activityType === 'medication') {
|
||||
if (!medicineName) {
|
||||
setError(t('health.medicineName.required'));
|
||||
showError({ message: t('health.medicineName.required'), code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
const dosageValue = unit === 'ml' ? dosage : dosageText;
|
||||
if (!dosageValue || (unit === 'ml' && dosage === 0) || (unit !== 'ml' && !dosageText)) {
|
||||
setError(t('health.dosage.required'));
|
||||
showError({ message: t('health.dosage.required'), code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
} else if (activityType === 'temperature') {
|
||||
if (temperature === 0) {
|
||||
setError('Please enter temperature');
|
||||
showError({ message: 'Please enter temperature', code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
} else if (activityType === 'doctor') {
|
||||
if (!visitType) {
|
||||
setError('Please select visit type');
|
||||
showError({ message: 'Please select visit type', code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
clearError();
|
||||
|
||||
let data: MedicationData | TemperatureData | DoctorVisitData;
|
||||
|
||||
@@ -253,7 +255,7 @@ function MedicalTrackPage() {
|
||||
await loadRecentActivities();
|
||||
} catch (err: any) {
|
||||
console.error('Failed to save activity:', err);
|
||||
setError(err.response?.data?.message || 'Failed to save activity');
|
||||
showError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -299,7 +301,7 @@ function MedicalTrackPage() {
|
||||
await loadRecentActivities();
|
||||
} catch (err: any) {
|
||||
console.error('Failed to delete activity:', err);
|
||||
setError(err.response?.data?.message || 'Failed to delete activity');
|
||||
showError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -446,9 +448,9 @@ function MedicalTrackPage() {
|
||||
/>
|
||||
</Box>
|
||||
|
||||
{error && (
|
||||
<Alert severity="error" sx={{ mb: 3 }} onClose={() => setError(null)}>
|
||||
{error}
|
||||
{hasError && (
|
||||
<Alert severity="error" sx={{ mb: 3 }} onClose={clearError}>
|
||||
{formatErrorMessage(error)}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
|
||||
@@ -47,6 +47,8 @@ import { childrenApi, Child } from '@/lib/api/children';
|
||||
import { motion } from 'framer-motion';
|
||||
import { useLocalizedDate } from '@/hooks/useLocalizedDate';
|
||||
import { useTranslation } from '@/hooks/useTranslation';
|
||||
import { useErrorMessage } from '@/components/common/ErrorMessage';
|
||||
import { formatErrorMessage } from '@/lib/utils/errorHandler';
|
||||
import { useDispatch, useSelector } from 'react-redux';
|
||||
import { fetchChildren, selectChild, selectSelectedChild, childrenSelectors } from '@/store/slices/childrenSlice';
|
||||
import { AppDispatch, RootState } from '@/store/store';
|
||||
@@ -91,7 +93,7 @@ export default function SleepTrackPage() {
|
||||
const [recentSleeps, setRecentSleeps] = useState<Activity[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [sleepsLoading, setSleepsLoading] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const { error, showError, clearError, hasError } = useErrorMessage();
|
||||
const [successMessage, setSuccessMessage] = useState<string | null>(null);
|
||||
|
||||
// Delete confirmation dialog
|
||||
@@ -181,18 +183,18 @@ export default function SleepTrackPage() {
|
||||
|
||||
const handleSubmit = async () => {
|
||||
if (!selectedChild?.id) {
|
||||
setError('Please select a child');
|
||||
showError({ message: 'Please select a child', code: 'NO_CHILD_SELECTED' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Validation
|
||||
if (!startTime) {
|
||||
setError('Please enter start time');
|
||||
showError({ message: 'Please enter start time', code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isOngoing && !endTime) {
|
||||
setError('Please enter end time or mark as ongoing');
|
||||
showError({ message: 'Please enter end time or mark as ongoing', code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -200,14 +202,14 @@ export default function SleepTrackPage() {
|
||||
const start = new Date(startTime);
|
||||
const end = new Date(endTime);
|
||||
if (end <= start) {
|
||||
setError('End time must be after start time');
|
||||
showError({ message: 'End time must be after start time', code: 'VALIDATION_ERROR' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
clearError();
|
||||
|
||||
const data: SleepData = {
|
||||
startTime,
|
||||
@@ -236,7 +238,7 @@ export default function SleepTrackPage() {
|
||||
await loadRecentSleeps();
|
||||
} catch (err: any) {
|
||||
console.error('Failed to save sleep:', err);
|
||||
setError(err.response?.data?.message || 'Failed to save sleep');
|
||||
showError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -268,7 +270,7 @@ export default function SleepTrackPage() {
|
||||
await loadRecentSleeps();
|
||||
} catch (err: any) {
|
||||
console.error('Failed to delete sleep:', err);
|
||||
setError(err.response?.data?.message || 'Failed to delete sleep');
|
||||
showError(err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -380,9 +382,9 @@ export default function SleepTrackPage() {
|
||||
</Typography>
|
||||
</Box>
|
||||
|
||||
{error && (
|
||||
<Alert severity="error" sx={{ mb: 3 }} onClose={() => setError(null)}>
|
||||
{error}
|
||||
{hasError && (
|
||||
<Alert severity="error" sx={{ mb: 3 }} onClose={clearError}>
|
||||
{formatErrorMessage(error)}
|
||||
</Alert>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user