fix: profile page form pre-population and WSDC ID editing
- Add useEffect to pre-fill profile form with current user data - Add WSDC ID field to profile edit form with numeric validation - Update backend to accept wsdcId in profile updates with null handling - Add wsdcId validation to updateProfileValidation middleware - Include firstName, lastName, wsdcId in GET /api/users/me response Fixes issue where profile inputs were empty on page load and allows users to update their WSDC ID.
This commit is contained in:
@@ -10,12 +10,13 @@ const { sanitizeForEmail } = require('../utils/sanitize');
|
||||
async function updateProfile(req, res, next) {
|
||||
try {
|
||||
const userId = req.user.id;
|
||||
const { firstName, lastName, email } = req.body;
|
||||
const { firstName, lastName, email, wsdcId } = req.body;
|
||||
|
||||
// Build update data
|
||||
const updateData = {};
|
||||
if (firstName !== undefined) updateData.firstName = firstName;
|
||||
if (lastName !== undefined) updateData.lastName = lastName;
|
||||
if (wsdcId !== undefined) updateData.wsdcId = wsdcId || null; // Allow empty string to clear WSDC ID
|
||||
|
||||
// Check if email is being changed
|
||||
const currentUser = await prisma.user.findUnique({
|
||||
|
||||
@@ -131,6 +131,11 @@ const updateProfileValidation = [
|
||||
.isEmail()
|
||||
.withMessage('Must be a valid email address')
|
||||
.normalizeEmail(),
|
||||
body('wsdcId')
|
||||
.optional()
|
||||
.trim()
|
||||
.matches(/^\d{0,10}$/)
|
||||
.withMessage('WSDC ID must be numeric and up to 10 digits'),
|
||||
handleValidationErrors,
|
||||
];
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ router.get('/me', authenticate, async (req, res, next) => {
|
||||
username: true,
|
||||
email: true,
|
||||
emailVerified: true,
|
||||
firstName: true,
|
||||
lastName: true,
|
||||
wsdcId: true,
|
||||
avatar: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
|
||||
Reference in New Issue
Block a user