Skip to content

Commit

Permalink
adding code so that after the user saves their preferences the app na…
Browse files Browse the repository at this point in the history
…vigates back to the profile page.
  • Loading branch information
WelldoneM committed Oct 17, 2024
1 parent 68ba805 commit f35e89b
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions src/components/Profile/TimePreferencesPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,44 @@ import { useTimePreferences } from '@data/useTimePreferences';
import { Box, Typography, Button, CircularProgress } from '@mui/material';

import TimePreferencesGrid from './TimePreferencesGrid';
import { useAuthState } from '@auth/useAuthState';
import { useNavigate } from "react-router-dom";

export default function TimePreferencesPage() {
const { selectedTimes, setSelectedTimes, loading, savePreferences } = useTimePreferences();
const [user] = useAuthState();
const { selectedTimes, setSelectedTimes, loading, savePreferences } = useTimePreferences();
const navigate = useNavigate();

// Function to save preferences and navigate back to profile page
const handleSavePreferences = async () => {
await savePreferences();
navigate(`/profile/${user.uid}`);

};

if (loading) {
return (
<Box
sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}
>
<CircularProgress />
</Box>
);
}

// Function to save preferences and navigate back to profile page
const handleSavePreferences = async () => {
await savePreferences();
};

if (loading) {
return (
<Box
sx={{ display: 'flex', justifyContent: 'center', alignItems: 'center', height: '100vh' }}
>
<CircularProgress />
</Box>
<Box sx={{ maxWidth: 800, margin: 'auto', padding: 3, alignItems: 'center' }}>
<Typography variant="h4" align="center" gutterBottom>
Time Preferences
</Typography>

<TimePreferencesGrid selectedTimes={selectedTimes} setSelectedTimes={setSelectedTimes} />

<Box sx={{ display: 'flex', justifyContent: 'center', marginTop: 2 }}>
<Button variant="contained" onClick={handleSavePreferences}>
Save Preferences
</Button>
</Box>
</Box>
);
}

return (
<Box sx={{ maxWidth: 800, margin: 'auto', padding: 3, alignItems: 'center' }}>
<Typography variant="h4" align="center" gutterBottom>
Time Preferences
</Typography>

<TimePreferencesGrid selectedTimes={selectedTimes} setSelectedTimes={setSelectedTimes} />

<Box sx={{ display: 'flex', justifyContent: 'center', marginTop: 2 }}>
<Button variant="contained" onClick={handleSavePreferences}>
Save Preferences
</Button>
</Box>
</Box>
);
}

0 comments on commit f35e89b

Please sign in to comment.