Skip to content

Commit 4e99ac9

Browse files
committed
Assistants can now apply to jobs succefully
1 parent 349ff35 commit 4e99ac9

File tree

4 files changed

+73
-44
lines changed

4 files changed

+73
-44
lines changed

.firebase/hosting.ZGlzdA.cache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
favicon.png,1742999374775,e73ad37e8e066e7c600db58733033ab0b4e0b9ce7312e0c1e62435dedddfb108
22
404.html,1742999374775,41d1e074106979fb6591ec6953bfe5ace2788be22f0ed4189bd54905ebb5b44d
3-
index.html,1744493021839,9851aaaf74806c33d3189720193040f64fdd2ba18a77843c6dff6758ddce776a
4-
assets/index-67ce75d8.css,1744493021839,9e2b4567a3922ff6483f5b4f351f0c6ad76297f5874238ed01b6440efe43718a
5-
assets/index-f949cbaa.js,1744493021842,2ecdb173a05ea224ea375669a2f2b7e9e83df894fba3246e94c960a9aad2d188
3+
index.html,1744576655250,e1e9dc94a7406f49e25275ce3f24cbaa4d4f16800b5b52485600f1f62cd47700
4+
assets/index-67ce75d8.css,1744576655250,9e2b4567a3922ff6483f5b4f351f0c6ad76297f5874238ed01b6440efe43718a
5+
assets/index-5bf94bec.js,1744576655252,2b7e52d4fda2b9082be26e0fff4bc55f730078d66b2bb08eb1deaa31345500a7
Lines changed: 25 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
88
<title>ResearchFinder</title>
9-
<script type="module" crossorigin src="/assets/index-f949cbaa.js"></script>
9+
<script type="module" crossorigin src="/assets/index-5bf94bec.js"></script>
1010
<link rel="stylesheet" href="/assets/index-67ce75d8.css">
1111
</head>
1212
<body>

src/components/Apply.jsx

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useParams } from 'react-router-dom';
33
import axios from 'axios';
44

55
const Apply = ({ assistantId }) => {
6-
const { id: postId } = useParams(); // URL param for the post
6+
const { id: postId } = useParams(); // Extract postId from URL
77
const [message, setMessage] = useState('');
88
const [status, setStatus] = useState(null);
99
const [loading, setLoading] = useState(false);
@@ -14,16 +14,28 @@ const Apply = ({ assistantId }) => {
1414
setStatus(null);
1515

1616
try {
17+
const trimmedMessage = message.trim();
18+
if (!trimmedMessage) {
19+
setStatus("❗ Message cannot be empty.");
20+
setLoading(false);
21+
return;
22+
}
23+
1724
const res = await axios.post('https://research-finder-server.vercel.app/applications', {
1825
assistantId,
1926
postId,
20-
message,
27+
message: trimmedMessage,
2128
});
2229

23-
setStatus('✅ Application submitted successfully!');
30+
if (res.status === 201) {
31+
setStatus('✅ Application submitted successfully!');
32+
setMessage(''); // Clear message after success
33+
} else {
34+
setStatus('⚠️ Unexpected response. Try again later.');
35+
}
2436
} catch (err) {
2537
console.error('❌ Application error:', err.response?.data || err.message);
26-
setStatus('❌ Failed to submit application.');
38+
setStatus(`❌ Failed to submit application: ${err.response?.data?.error || err.message}`);
2739
} finally {
2840
setLoading(false);
2941
}
@@ -33,23 +45,40 @@ const Apply = ({ assistantId }) => {
3345
<div style={{ padding: '2rem', maxWidth: '600px', margin: '0 auto' }}>
3446
<h2>Apply to Research Opportunity</h2>
3547
<form onSubmit={handleSubmit}>
36-
<label>
48+
<label htmlFor="application-message">
3749
Why are you interested?
38-
<textarea
39-
rows="5"
40-
value={message}
41-
onChange={(e) => setMessage(e.target.value)}
42-
required
43-
style={{ width: '100%', marginTop: '0.5rem' }}
44-
/>
4550
</label>
46-
<br />
47-
<button type="submit" disabled={loading} style={{ marginTop: '1rem' }}>
51+
<textarea
52+
id="application-message"
53+
rows="5"
54+
value={message}
55+
onChange={(e) => setMessage(e.target.value)}
56+
required
57+
placeholder="Write your message here..."
58+
style={{ width: '100%', marginTop: '0.5rem', padding: '0.5rem' }}
59+
/>
60+
<button
61+
type="submit"
62+
disabled={loading}
63+
style={{
64+
marginTop: '1rem',
65+
padding: '0.5rem 1rem',
66+
backgroundColor: '#007bff',
67+
color: 'white',
68+
border: 'none',
69+
borderRadius: '5px',
70+
cursor: 'pointer'
71+
}}
72+
>
4873
{loading ? 'Submitting...' : 'Submit Application'}
4974
</button>
5075
</form>
5176

52-
{status && <p style={{ marginTop: '1rem', fontWeight: 'bold' }}>{status}</p>}
77+
{status && (
78+
<p style={{ marginTop: '1rem', fontWeight: 'bold', color: status.startsWith('✅') ? 'green' : 'red' }}>
79+
{status}
80+
</p>
81+
)}
5382
</div>
5483
);
5584
};

0 commit comments

Comments
 (0)