Skip to content
Open
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
63 changes: 43 additions & 20 deletions newsletter-sign-up-with-success-message-main/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- displays site properly based on user's device -->

<link rel="icon" type="image/png" sizes="32x32" href="./assets/images/favicon-32x32.png">

<link rel="stylesheet" href="./style.css">
<title>Frontend Mentor | Newsletter sign-up form with success message</title>


<!-- Feel free to remove these styles or customise in your own stylesheet 👍 -->
<style>
.attribution { font-size: 11px; text-align: center; }
Expand All @@ -17,36 +18,58 @@
<body>

<!-- Sign-up form start -->
<div class="main-card" id="signup-card">
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need both id and classes? you can use 2 classes

Copy link
Author

Choose a reason for hiding this comment

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

there is no special reason, its just that I'm familiar with it

Copy link
Member

Choose a reason for hiding this comment

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

It would be better to not always use id, only for spesific cases

<div class="text-section">
<h1 id="headline">Stay updated!</h1>

Stay updated!

Join 60,000+ product managers receiving monthly updates on:
<p class="description">Join 60,000+ product managers receiving
monthly updates on:</p>

<ul class="info-list">
<li class="list-item"><img src="./assets/images/icon-list.svg" alt="checkmark icon" class="list-icon"> Product discovery and building what matters</li>
<li class="list-item"><img src="./assets/images/icon-list.svg" alt="checkmark icon" class="list-icon"> Measuring to ensure updates are a success</li>
<li class="list-item"><img src="./assets/images/icon-list.svg" alt="checkmark icon" class="list-icon"> And much more!</li>
</ul>

Product discovery and building what matters
Measuring to ensure updates are a success
And much more!
<div class="email-block">
<div class="email-label-block">
<p id="email-label">Email address</p>
<p class="error-message hidden" id="error-message">Valid email required</p>
</div>
<input type="email" id="email-input" placeholder="email@company.com">
</div>

Email address
email@company.com
<button class="subscribe-button" id="submit-button">Subscribe to monthly newsletter</button>

Subscribe to monthly newsletter

<!-- Sign-up form end -->
</div>
<div class="image-section">
<img src="./assets/images/illustration-sign-up-desktop.svg" alt="information illustration">
</div>
</div>

<!-- Success message start -->
<div class="main-card hidden" id="success-card">
<div class="success-section">
<img src="./assets/images/icon-success.svg" alt="success icon" class="success-icon">
<h1 class="success-title">Thanks for subscribing!</h1>

<p class="success-message">A confirmation email has been sent to <strong id="user-email">ash@loremcompany.com</strong>.
Please open it and click the button inside to confirm your subscription.</p>

Thanks for subscribing!

A confirmation email has been sent to ash@loremcompany.com.
Please open it and click the button inside to confirm your subscription.
<button class="dismiss-button" id="dismiss-button">Dismiss message</button>
</div>
</div>
<!-- Success message end -->

Dismiss message
<!-- Sign-up form end -->

<!-- Success message end -->

<div class="attribution">
<!-- <div class="attribution">
Copy link
Member

Choose a reason for hiding this comment

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

Do not comment your code, delete it.
we can always check the history via git

Challenge by <a href="https://www.frontendmentor.io?ref=challenge" target="_blank">Frontend Mentor</a>.
Coded by <a href="#">Your Name Here</a>.
</div>
</div> -->


<script src ="./script.js"></script>
</body>
</html>
91 changes: 91 additions & 0 deletions newsletter-sign-up-with-success-message-main/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Getting elements
Copy link
Member

Choose a reason for hiding this comment

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

The first thing that came to my mind is "ok so this entire page was generated by ai"

You don't need all of those commends, this is a really bad practice
comments that explain what the code is doing are bad comments, or the code is bad and need clarification

Am i wrong to assume that this is ai code?

Copy link
Author

Choose a reason for hiding this comment

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

not entirely I've used ai here for 2 things

  1. comments
  2. adding the fonts

const emailInput = document.getElementById('email-input');
const submitButton = document.getElementById('submit-button');
const dismissButton = document.getElementById('dismiss-button');
const signupCard = document.getElementById('signup-card');
const successCard = document.getElementById('success-card');
const errorMessage = document.getElementById('error-message');
const userEmailSpan = document.getElementById('user-email');


// Show error state
function showError() {
errorMessage.classList.remove('hidden');
emailInput.classList.add('error-input');
}

// Hide error state
function hideError() {
errorMessage.classList.add('hidden');
emailInput.classList.remove('error-input');
}

// Switch to success stage
const showSuccessMessage = (email) => {
signupCard.classList.add('hidden');
successCard.classList.remove('hidden');
userEmailSpan.textContent = email;
Copy link
Member

Choose a reason for hiding this comment

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

You should check that your email if defined

};

// Switch to signup stage
function showSignupStage() {
successCard.classList.add('hidden');
signupCard.classList.remove('hidden');
emailInput.value = '';
hideError();
}

// Email validation function
const validateEmail = (email) => {
const domain = email.split('@')[1];
const emailDomain = ['gmail.com', 'yahoo.com', 'outlook.com', 'hotmail.com', 'collman.com'];

if (email === '' || !email.includes('@')) {
showError();
return false;
}
if (!emailDomain.includes(domain)) {
showError();
return false;
} else {
Copy link
Member

Choose a reason for hiding this comment

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

In your if you have a return statement so you dont really need the else

Also you have 2 ifs that are doing exactly the same thing.
You can save the conditions inside a variables and combine those into single if with no else

hideError();
}

return true;
};
// "Enable/disable" submit button based on email validity
emailInput.addEventListener('input', updateButtonState);

function updateButtonState() {
const email = emailInput.value.trim();
if (validateEmail(email)) {
submitButton.classList.add('enabled-button');
} else {
submitButton.classList.remove('enabled-button');
}
}

// Handle form submission
submitButton.addEventListener('click', (e) => {
e.preventDefault();

const email = emailInput.value.trim();

// Validate email
if (validateEmail(email)) {
showSuccessMessage(email);
}
});

// Handle dismiss button

dismissButton.addEventListener('click', function() {
showSignupStage();
});

// Hide error when user starts typing
emailInput.addEventListener('input', function() {
if (!errorMessage.classList.contains('hidden')) {
hideError();
}
});
161 changes: 161 additions & 0 deletions newsletter-sign-up-with-success-message-main/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
@font-face {
font-family: 'Roboto';
src: url('./assets/fonts/Roboto-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
Copy link
Member

Choose a reason for hiding this comment

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

Why did you add those attributes?

}

@font-face {
font-family: 'Roboto';
src: url('./assets/fonts/Roboto-Bold.ttf') format('truetype');
font-weight: bold;
font-style: normal;
Copy link
Member

Choose a reason for hiding this comment

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

This is the exact same code as above, remove it

}

body{
font-family: 'Roboto', Arial, sans-serif;
display: flex;
justify-content: center;
align-items: center;

background-color: hsl(234, 29%, 20%);
Copy link
Member

Choose a reason for hiding this comment

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

Colors should come from css variables and not inline like this

height: 100vh;
font-size: 16px;
}
.main-card{
display: flex;
flex-direction: row;
background-color: hsl(0, 0%, 100%);
Copy link
Member

Choose a reason for hiding this comment

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

Same comment for all of the colors in this page

border: 1px solid hsl(234, 29%, 20%);
border-radius: 30px;
box-shadow: 0px 15px 25px rgba(0, 0, 0, 0.2);
padding: 20px;
}
.text-section{
padding: 50px;
}
#headline{
font-size: 55px;
display: flex;
justify-content: start;
color: hsl(234, 29%, 20%);
font-weight: bold;
}
.description{
font-size: 16px;
margin-bottom: 30px;

}
.info-list {
list-style: none;
padding-left: 0;
margin-bottom: 30px;
}
.list-icon {
margin-right: 10px;
}
.list-item {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.email-label-block {
display: flex;
flex-direction: row;
}
.email-block{
width: 100%;
gap: 10px;
margin-top: 20px;
}
#email-label{
font-size: 12px;
margin-bottom: 10px;
}
#email-input{
width: 100%;
padding: 12px 15px;
margin-bottom:20px;
border-radius: 5px;
border: 1px solid hsl(0, 0%,58%);
box-sizing: border-box;
}
.subscribe-button{
width: 100%;
background-color: hsl(234, 29%, 20%);
color: hsl(0, 0%, 100%);
border: none;
padding: 15px;
border-radius: 5px;
cursor: pointer;
}
.enabled-button{
transition: background 0.3s ease;
/*adding gradient to button*/
Copy link
Member

Choose a reason for hiding this comment

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

So this is ai generated? or you wrote it?
Any way remove it because comments like this are bad practice

Copy link
Author

Choose a reason for hiding this comment

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

no no thats me not ai

background: linear-gradient(90deg, hsl(4, 100%, 67%), hsl(22, 90%, 66%));
}

.hidden {
display: none;
}

/* Error States */
Copy link
Member

Choose a reason for hiding this comment

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

My comment about comments in code apply to this entire page

.error-message {

color: hsl(4, 100%, 67%);
font-size: 12px;
margin-bottom: 8px;
font-weight: bold;
margin-left: auto;
}

.error-input {
border-color: hsl(4, 100%, 67%);
background-color: hsl(4, 100%, 95%);
color: hsl(4, 100%, 67%);
}

/* Success Page Styles */
.success-section {
display: flex;
flex-direction: column;
align-items: flex-start;
padding: 50px;
max-width: 400px;
}

.success-icon {
width: 48px;
height: 48px;
margin-bottom: 30px;
}

.success-title {
font-size: 55px;
color: hsl(234, 29%, 20%);
font-weight: bold;
margin-bottom: 30px;
line-height: 1;
}

.success-message {
font-size: 16px;
line-height: 1.5;
margin-bottom: 40px;
color: hsl(234, 29%, 20%);
}

.dismiss-button {
width: 100%;
background-color: hsl(234, 29%, 20%);
color: hsl(0, 0%, 100%);
border: none;
padding: 15px;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
&:hover {
background: linear-gradient(90deg, hsl(4, 100%, 67%), hsl(22, 90%, 66%));
}
}