Skip to content

Commit 7a270ee

Browse files
committed
settings
1 parent a5869a6 commit 7a270ee

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

backend/users/serializers.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@ class ProfileSerializer(serializers.ModelSerializer):
2020
is_authenticated = serializers.BooleanField()
2121
followers = serializers.SerializerMethodField()
2222
following = serializers.SerializerMethodField()
23+
first_name = serializers.SerializerMethodField()
24+
last_name = serializers.SerializerMethodField()
2325

2426
class Meta:
2527
model = Profile
2628
fields = [
2729
'id', 'username', 'date_joined', 'image', 'is_anonymous', 'email',
28-
'is_authenticated', 'is_staff', 'followers', 'following'
30+
'is_authenticated', 'is_staff', 'followers', 'following',
31+
'first_name', 'last_name'
2932
]
3033

3134
def to_representation(self, instance):
@@ -48,6 +51,18 @@ def get_followers(self, obj):
4851
def get_following(self, obj):
4952
return FollowSerializer(obj.following.all(), many=True).data
5053

54+
def get_first_name(self, obj):
55+
user = self.context.get('request').user
56+
if user == obj.profile.user:
57+
return obj.profile.user.first_name
58+
return None
59+
60+
def get_last_name(self, obj):
61+
user = self.context.get('request').user
62+
if user == obj.profile.user:
63+
return obj.profile.user.last_name
64+
return None
65+
5166

5267
class ProfileBioSerializer(serializers.ModelSerializer):
5368
class Meta:

frontend/src/components/ProfileSettings.jsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import React, { useState, useContext, useEffect } from 'react';
22
import { useNavigate } from 'react-router-dom';
3-
import { Button, Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions, LinearProgress } from '@mui/material';
3+
import {
4+
Button,
5+
Dialog,
6+
DialogTitle,
7+
DialogContent,
8+
DialogContentText,
9+
DialogActions,
10+
LinearProgress,
11+
Typography,
12+
Box,
13+
} from '@mui/material';
414
import api from '../utils/api';
515
import UserContext from './contexts/UserContext';
6-
import { handleLogout } from '../utils/auth'; // Import handleLogout
16+
import { handleLogout } from '../utils/auth';
717

818
const ProfileSettings = () => {
919
const [open, setOpen] = useState(false);
@@ -47,8 +57,13 @@ const ProfileSettings = () => {
4757
}
4858

4959
return (
50-
<div className="container">
51-
<h2>Profile Settings</h2>
60+
<Box className="container">
61+
<Typography variant="h4" gutterBottom>
62+
Profile Settings
63+
</Typography>
64+
<Typography variant="h6" gutterBottom>
65+
Welcome, {user.first_name} {user.last_name}!
66+
</Typography>
5267
<Button variant="contained" color="error" onClick={handleClickOpen}>
5368
Delete Profile
5469
</Button>
@@ -61,7 +76,10 @@ const ProfileSettings = () => {
6176
<DialogContentText>Profile deleted successfully!</DialogContentText>
6277
) : (
6378
<DialogContentText>
64-
Are you sure you want to delete your profile? This action cannot be undone.
79+
Are you sure you want to delete your profile, {user.first_name}?
80+
<Typography variant="body1" fontWeight="bold" component="div" gutterBottom>
81+
This action cannot be undone.
82+
</Typography>
6583
</DialogContentText>
6684
)}
6785
</DialogContent>
@@ -76,7 +94,7 @@ const ProfileSettings = () => {
7694
)}
7795
</DialogActions>
7896
</Dialog>
79-
</div>
97+
</Box>
8098
);
8199
};
82100

0 commit comments

Comments
 (0)