-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
got rid of inline styling for page components, refactored App.css and…
… index.css for /grant-info
- Loading branch information
1 parent
7a5e8c9
commit 918f095
Showing
11 changed files
with
343 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,74 @@ | ||
// src/Login.tsx | ||
|
||
import React, { useState } from 'react'; | ||
import { setAuthentication } from './external/bcanSatchel/actions'; // Corrected import path | ||
import { observer } from 'mobx-react-lite'; | ||
import { useNavigate } from 'react-router-dom'; | ||
import './styles/Login.css'; | ||
|
||
const Login = observer(() => { | ||
const [username, setUsername] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const navigate = useNavigate(); | ||
const [username, setUsername] = useState(''); | ||
const [password, setPassword] = useState(''); | ||
const navigate = useNavigate(); | ||
|
||
const handleSubmit = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
const handleSubmit = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
|
||
try { | ||
const response = await fetch('http://localhost:3001/auth/login', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ username, password }), | ||
}); | ||
try { | ||
const response = await fetch('http://localhost:3001/auth/login', { | ||
method: 'POST', | ||
headers: { 'Content-Type': 'application/json' }, | ||
body: JSON.stringify({ username, password }), | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
alert(errorData.message || 'Login failed. Please check your credentials.'); | ||
return; | ||
} | ||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
alert(errorData.message || 'Login failed. Please check your credentials.'); | ||
return; | ||
} | ||
|
||
const data = await response.json(); | ||
console.log('Login response data:', data); | ||
const data = await response.json(); | ||
console.log('Login response data:', data); | ||
|
||
if (data.access_token) { | ||
setAuthentication(true, data.user, data.access_token); | ||
navigate('/dashboard'); | ||
alert(data.message); // Alert wit message from backend indicating success | ||
} else { | ||
alert('Login failed. Please check your credentials.'); | ||
} | ||
} catch (error) { | ||
console.error('Error during login:', error); | ||
alert('An error occurred while logging in. Please try again later.'); | ||
} | ||
}; | ||
if (data.access_token) { | ||
setAuthentication(true, data.user, data.access_token); | ||
navigate('/dashboard'); | ||
alert(data.message); // Alert with message from backend indicating success | ||
} else { | ||
alert('Login failed. Please check your credentials.'); | ||
} | ||
} catch (error) { | ||
console.error('Error during login:', error); | ||
alert('An error occurred while logging in. Please try again later.'); | ||
} | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit} style={{ maxWidth: '400px', | ||
margin: '0 auto', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
border: '1px solid #ccc', | ||
borderRadius: '8px', | ||
padding: '20px 30px'}}> | ||
<h2>Login</h2> | ||
<div> | ||
<label style={{ display: 'block', textAlign: 'left' }}>Username</label> | ||
<input | ||
type="text" | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
required | ||
style={{width: '90%', | ||
padding: '8px', | ||
margin: '8px 0'}} | ||
/> | ||
</div> | ||
<div> | ||
<label style={{ display: 'block', textAlign: 'left' }} >Password</label> | ||
<input | ||
type="password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
required | ||
style={{ width: '90%', padding: '8px', margin: '8px 0'}} | ||
/> | ||
|
||
</div> | ||
<button | ||
type="submit" | ||
style={{ padding: '8px', width :'100%', margin: '8px 0', backgroundColor: 'black', color: 'white'}}> | ||
Login | ||
</button> | ||
<button | ||
type="submit" | ||
style={{ padding: '8px', width :'100%', margin: '8px 0', backgroundColor: 'white', color: 'black'}}> | ||
Forgot Password? | ||
</button> | ||
</form> | ||
); | ||
return ( | ||
<form onSubmit={handleSubmit} className="login-form"> | ||
<h2 className="login-heading">Login</h2> | ||
<div> | ||
<label className="login-label">Username</label> | ||
<input | ||
type="text" | ||
value={username} | ||
onChange={(e) => setUsername(e.target.value)} | ||
required | ||
className="login-input" | ||
/> | ||
</div> | ||
<div> | ||
<label className="login-label">Password</label> | ||
<input | ||
type="password" | ||
value={password} | ||
onChange={(e) => setPassword(e.target.value)} | ||
required | ||
className="login-input" | ||
/> | ||
</div> | ||
<button type="submit" className="login-button">Login</button> | ||
<button type="button" className="login-button-forgot">Forgot Password?</button> | ||
</form> | ||
); | ||
}); | ||
|
||
export default Login; | ||
export default Login; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,72 @@ | ||
// src/Profile.tsx | ||
|
||
import React, { useState } from 'react'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { getStore } from './external/bcanSatchel/store'; | ||
import { updateUserProfile } from './external/bcanSatchel/actions'; | ||
import './styles/Profile.css'; | ||
|
||
const Profile = observer(() => { | ||
const store = getStore(); | ||
const [email, setEmail] = useState(store.user?.email || ''); | ||
const [biography, setBiography] = useState(store.user?.biography || ''); | ||
const store = getStore(); | ||
const [email, setEmail] = useState(store.user?.email || ''); | ||
const [biography, setBiography] = useState(store.user?.biography || ''); | ||
|
||
const handleSubmit = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
const handleSubmit = async (e: React.FormEvent) => { | ||
e.preventDefault(); | ||
|
||
try { | ||
const response = await fetch('http://localhost:3001/user/me', { | ||
method: 'PUT', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${store.accessToken}`, | ||
}, | ||
body: JSON.stringify({ email, biography }), | ||
}); | ||
try { | ||
const response = await fetch('http://localhost:3001/user/me', { | ||
method: 'PUT', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${store.accessToken}`, | ||
}, | ||
body: JSON.stringify({ email, biography }), | ||
}); | ||
|
||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
alert(errorData.message || 'Failed to update profile.'); | ||
return; | ||
} | ||
if (!response.ok) { | ||
const errorData = await response.json(); | ||
alert(errorData.message || 'Failed to update profile.'); | ||
return; | ||
} | ||
|
||
const data = await response.json(); | ||
const data = await response.json(); | ||
|
||
updateUserProfile(data); | ||
alert('Profile updated successfully.'); | ||
} catch (error) { | ||
console.error('Error updating profile:', error); | ||
alert('An error occurred while updating your profile.'); | ||
} | ||
}; | ||
updateUserProfile(data); | ||
alert('Profile updated successfully.'); | ||
} catch (error) { | ||
console.error('Error updating profile:', error); | ||
alert('An error occurred while updating your profile.'); | ||
} | ||
}; | ||
|
||
return ( | ||
<form onSubmit={handleSubmit} style={{maxWidth: '600px', | ||
margin: '0 auto', | ||
border: '1px solid #ccc', | ||
borderRadius: '8px', | ||
padding: '20px 30px' }}> | ||
<h2>Profile</h2> | ||
<div style = {{padding: '5px'}} > | ||
|
||
<label >Username: </label> | ||
<span>{store.user?.userId}</span> | ||
</div> | ||
<div> | ||
<label>Email:</label> | ||
<input | ||
type="email" | ||
style={{ width: '100%', padding: '8px', margin: '8px 0' }} | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
required | ||
/> | ||
</div> | ||
<div> | ||
<label>Biography:</label> | ||
<textarea | ||
style={{ width: '100%', padding: '8px', margin: '8px 0' }} | ||
value={biography} | ||
onChange={(e) => setBiography(e.target.value)} | ||
></textarea> | ||
</div> | ||
<button type="submit" style={{ padding: '10px', fontSize: '16px' }}> | ||
Save Changes | ||
</button> | ||
</form> | ||
); | ||
return ( | ||
<form onSubmit={handleSubmit} className="profile-form"> | ||
<h2 className="profile-heading">Profile</h2> | ||
<div className="profile-section"> | ||
<label className="profile-label">Username:</label> | ||
<span>{store.user?.userId}</span> | ||
</div> | ||
<div className="profile-section"> | ||
<label className="profile-label">Email:</label> | ||
<input | ||
type="email" | ||
className="profile-input" | ||
value={email} | ||
onChange={(e) => setEmail(e.target.value)} | ||
required | ||
/> | ||
</div> | ||
<div className="profile-section"> | ||
<label className="profile-label">Biography:</label> | ||
<textarea | ||
className="profile-input" | ||
value={biography} | ||
onChange={(e) => setBiography(e.target.value)} | ||
></textarea> | ||
</div> | ||
<button type="submit" className="profile-button">Save Changes</button> | ||
</form> | ||
); | ||
}); | ||
|
||
export default Profile; | ||
export default Profile; |
Oops, something went wrong.