Skip to content
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

Minor adjustments remove console statements #20

Merged
merged 2 commits into from
Mar 6, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,6 @@ Also I would like to thank [Murat Korkmaz](https://www.behance.net/muratk) on Be

## 📝 License <a name="license"></a>

This project is [MIT](https://github.com/tsheporamantso/final-capstone-react-front-end/blob/1012050f1dd1a177d317f0a8c3b90ab76d956a7f/LICENSE) licensed.
This project is [MIT](./LICENSE) licensed.

<p align="right">(<a href="#readme-top">back to top</a>)</p>
4 changes: 3 additions & 1 deletion src/Components/AddReservation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ function AddReservation() {
const [numberOfDays, setNumberOfDays] = useState(0);
const status = useSelector((state) => state.addReservation.status);
const error = useSelector((state) => state.addReservation.error);
const [errorMessage, setErrorMessage] = useState('');

const fetchPlaces = async (userId) => {
try {
const response = await fetch(`http://localhost:3000/api/v1/users/${userId}/places`);
const data = await response.json();
setPlaces(data);
} catch (error) {
console.error('Error fetching places:', error);
setErrorMessage('Invalid Email or password.');
}
};

Expand Down Expand Up @@ -77,6 +78,7 @@ function AddReservation() {
}}
>
<h2>Add Reservation</h2>
{errorMessage && <p style={{ color: 'red' }}>{errorMessage}</p>}
<input type="date" name="start_date" placeholder="Start Date" value={reservationData.start_date} onChange={handleChange} />
<br />
<input type="date" name="end_date" placeholder="End Date" value={reservationData.end_date} onChange={handleChange} />
Expand Down
13 changes: 0 additions & 13 deletions src/Components/UserAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,25 @@ function UserAuth({ setLoggedIn }) {

const handleSubmit = async (e) => {
e.preventDefault();
console.log('Form data:', { email, password });

try {
console.log('Submitting sign in form...');
const response = await axios.post('http://localhost:3000/users/sign_in', {
user: {
email,
password,
},
});

console.log('Response Data:', response.data);

console.log('I want the User ID', response.data.status.data.id);

if (response.status === 200) {
localStorage.setItem('authToken', response.data.token);
localStorage.setItem('userId', response.data.status.data.id);

const userId = localStorage.getItem('userId');
console.log('User ID from local storage:', userId);

setLoggedIn(true);
navigate('/layout/placelist');
} else {
console.error('Unexpected response status:', response.status);
setErrorMessage('Invalid Email or password.');
}
} catch (error) {
console.log('Error:', error.response.data);
console.error('Axios error:', error);
setErrorMessage('Invalid Email or password.');
}
};
Expand All @@ -52,7 +40,6 @@ function UserAuth({ setLoggedIn }) {
<h1>Sign In</h1>
{errorMessage && <p style={{ color: 'red' }}>{errorMessage}</p>}
{' '}
{/* Display error message */}
<form onSubmit={handleSubmit}>
<input className="mail-border" type="email" placeholder="Email" value={email} onChange={(e) => setEmail(e.target.value)} />
<br />
Expand Down
12 changes: 6 additions & 6 deletions src/Components/UserSignUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,30 @@ function UserSignUp() {
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [errorMessage, setErrorMessage] = useState('');
const navigate = useNavigate();
const handleSubmit = async (e) => {
e.preventDefault();

console.log('Form data:', { name, email, password });
try {
console.log('Submitting form...');
const response = await axios.post('http://localhost:3000/users', {
await axios.post('http://localhost:3000/users', {
user: {
name,
email,
password,
},
});
console.log('Response:', response.data);
navigate('/');
} catch (error) {
console.log('Error:', error.response.data);
console.error('Axios error:', error);
setErrorMessage('Invalid Email or password.');
}
};

return (
<>
<h1>Sign Up</h1>
{errorMessage && <p style={{ color: 'red' }}>{errorMessage}</p>}
{' '}
<form onSubmit={handleSubmit}>
<input className="mail-border" type="text" placeholder="Name" value={name} onChange={(e) => setName(e.target.value)} />
<br />
Expand Down
Loading