Skip to content

Debugging v1beta #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app/profile/profile.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@

.buttonContainer {
margin: 0 0 1.5rem 0;
}

.settingsContainer {
width: 100%;
max-width: 25rem;
}
16 changes: 13 additions & 3 deletions src/components/profileSettings/ProfileSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,25 @@ export const ProfileSettings = ({ currentUser }) => {
}));
};

const isUsernameValid = (username) => {
Copy link
Preview

Copilot AI May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The username validation function is duplicated across components. Consider extracting it into a shared utility module to reduce redundancy.

Copilot uses AI. Check for mistakes.

const usernameRegex = /^[a-zA-Z0-9_-]{3,20}$/; // Allows 3-20 characters, alphanumeric, hyphens, and underscores
return usernameRegex.test(username);
};

const validateForm = () => {
if (formData.username.length < 3) {
setError('Username must be at least 3 characters');
if (!isUsernameValid(formData.username)) {
setError(
'Username must be 3-20 characters and can only contain letters, numbers, hyphens, and underscores.'
);
return false;
}

const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if (!emailRegex.test(formData.email)) {
setError('Please enter a valid email address');
return false;
}

setError('');
return true;
};
Expand Down Expand Up @@ -136,11 +145,12 @@ export const ProfileSettings = ({ currentUser }) => {
<Button variant="aquamarine" onClick={handleEditClick}>
{isEditing ? 'Save Settings' : 'Edit Settings'}
</Button>
{error && <div className={styles.error}>{error}</div>}


<Button variant="red" onClick={handleDeleteClick}>
Delete Account
</Button>
{error && <div className={styles.error}>{error}</div>}
</div>
</div>
{showPasswordModal && (
Expand Down
5 changes: 5 additions & 0 deletions src/components/profileSettings/ProfileSettings.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
color: red;
margin: 1rem;
text-align: center;

}

.form {
Expand All @@ -23,3 +24,7 @@
gap: 1.5rem;
}

.mainContainer {

}

17 changes: 15 additions & 2 deletions src/components/signup/Signup.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@ export default function Signup() {
const [showPassword, setShowPassword] = useState(false);
const [showConfirmPassword, setShowConfirmPassword] = useState(false);

const isUsernameValid = (username) => {
const usernameRegex = /^[a-zA-Z0-9_-]{3,20}$/;
return usernameRegex.test(username);
};
Comment on lines +26 to +29
Copy link
Preview

Copilot AI May 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The username validation function is duplicated across components. Consider extracting it into a shared utility module to reduce redundancy.

Suggested change
const isUsernameValid = (username) => {
const usernameRegex = /^[a-zA-Z0-9_-]{3,20}$/;
return usernameRegex.test(username);
};
import { isUsernameValid } from '../../utils/validation';

Copilot uses AI. Check for mistakes.


const isFormValid = () => {
const { email, password, confirmPassword, username } = formData;
return (
email.trim() !== '' &&
password.trim() !== '' &&
confirmPassword.trim() !== '' &&
username.trim() !== '' &&
password === confirmPassword
password === confirmPassword &&
isUsernameValid(username)
);
};

Expand All @@ -51,6 +57,13 @@ export default function Signup() {
return;
}

if (!isUsernameValid(username)) {
setError(
'Username must be 3-20 characters and can only contain letters, numbers, hyphens, and underscores.'
);
return;
}

if (password !== confirmPassword) {
setError('Passwords do not match');
return;
Expand Down Expand Up @@ -145,7 +158,7 @@ export default function Signup() {
variant={isFormValid() ? 'blue' : 'disabled'}
disabled={!isFormValid()}
>
Signup
Sign Up
</Button>
</form>
</div>
Expand Down