Spaces:
Sleeping
Sleeping
Commit ·
026c476
1
Parent(s): 4012449
Update IRIS full form and fix applicant message notifications
Browse files- src/components/ApplicantLayout.jsx +91 -44
- src/pages/LoginPage.jsx +1 -1
src/components/ApplicantLayout.jsx
CHANGED
|
@@ -80,20 +80,49 @@ export default function ApplicantLayout({ children, activePage, onNavigate }) {
|
|
| 80 |
|
| 81 |
const { data: messages } = await supabase
|
| 82 |
.from("messages")
|
| 83 |
-
.select("id, sender_id, content, created_at
|
| 84 |
.eq("receiver_id", user.id)
|
| 85 |
.eq("is_read", false)
|
| 86 |
.order("created_at", { ascending: false });
|
| 87 |
|
| 88 |
-
if (messages) {
|
| 89 |
setUnreadMessages(messages.length);
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
setUnreadMessagesList(formattedMessages);
|
| 98 |
}
|
| 99 |
};
|
|
@@ -128,41 +157,55 @@ export default function ApplicantLayout({ children, activePage, onNavigate }) {
|
|
| 128 |
|
| 129 |
// ⭐ NEW: realtime update for new messages
|
| 130 |
useEffect(() => {
|
|
|
|
| 131 |
|
| 132 |
-
const
|
| 133 |
-
.
|
| 134 |
-
|
| 135 |
-
"postgres_changes",
|
| 136 |
-
{ event: "INSERT", schema: "public", table: "messages" },
|
| 137 |
-
async (payload) => {
|
| 138 |
-
console.log("=== MESSAGES PAYLOAD ===", payload);
|
| 139 |
-
|
| 140 |
-
// Fetch the sender's name and add to the list
|
| 141 |
-
const { data: senderProfile } = await supabase
|
| 142 |
-
.from("profiles")
|
| 143 |
-
.select("full_name")
|
| 144 |
-
.eq("id", payload.new.sender_id)
|
| 145 |
-
.single();
|
| 146 |
-
|
| 147 |
-
const newMsg = {
|
| 148 |
-
id: payload.new.id,
|
| 149 |
-
senderName: senderProfile?.full_name || 'Someone',
|
| 150 |
-
content: payload.new.content,
|
| 151 |
-
timestamp: new Date(payload.new.created_at).toLocaleDateString() + ' • ' + new Date(payload.new.created_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
| 152 |
-
};
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
const jobsChannel = supabase
|
| 168 |
.channel("jobs-badge")
|
|
@@ -272,10 +315,14 @@ export default function ApplicantLayout({ children, activePage, onNavigate }) {
|
|
| 272 |
)
|
| 273 |
.subscribe();
|
| 274 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
return () => {
|
| 276 |
-
supabase.removeChannel(channel);
|
| 277 |
-
supabase.removeChannel(jobsChannel);
|
| 278 |
-
supabase.removeChannel(appsChannel);
|
| 279 |
};
|
| 280 |
|
| 281 |
}, []);
|
|
|
|
| 80 |
|
| 81 |
const { data: messages } = await supabase
|
| 82 |
.from("messages")
|
| 83 |
+
.select("id, sender_id, content, created_at")
|
| 84 |
.eq("receiver_id", user.id)
|
| 85 |
.eq("is_read", false)
|
| 86 |
.order("created_at", { ascending: false });
|
| 87 |
|
| 88 |
+
if (messages && messages.length > 0) {
|
| 89 |
setUnreadMessages(messages.length);
|
| 90 |
+
|
| 91 |
+
// Fetch sender names from user_roles/companies
|
| 92 |
+
const senderIds = [...new Set(messages.map(m => m.sender_id))];
|
| 93 |
+
const { data: rolesData } = await supabase
|
| 94 |
+
.from("user_roles")
|
| 95 |
+
.select("user_id, name, company_id")
|
| 96 |
+
.in("user_id", senderIds);
|
| 97 |
+
|
| 98 |
+
let companiesData = [];
|
| 99 |
+
if (rolesData) {
|
| 100 |
+
const companyIds = [...new Set(rolesData.map(r => r.company_id).filter(Boolean))];
|
| 101 |
+
if (companyIds.length > 0) {
|
| 102 |
+
const { data: comp } = await supabase.from("companies").select("id, name").in("id", companyIds);
|
| 103 |
+
if (comp) companiesData = comp;
|
| 104 |
+
}
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
const formattedMessages = messages.map(msg => {
|
| 108 |
+
let senderName = 'Admin / HR';
|
| 109 |
+
const role = rolesData?.find(r => r.user_id === msg.sender_id);
|
| 110 |
+
if (role) {
|
| 111 |
+
senderName = role.name || 'HR';
|
| 112 |
+
if (role.company_id) {
|
| 113 |
+
const comp = companiesData.find(c => c.id === role.company_id);
|
| 114 |
+
if (comp) senderName = comp.name;
|
| 115 |
+
}
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
return {
|
| 119 |
+
id: msg.id,
|
| 120 |
+
senderName,
|
| 121 |
+
content: msg.content,
|
| 122 |
+
timestamp: new Date(msg.created_at).toLocaleDateString() + ' • ' + new Date(msg.created_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
| 123 |
+
};
|
| 124 |
+
});
|
| 125 |
+
|
| 126 |
setUnreadMessagesList(formattedMessages);
|
| 127 |
}
|
| 128 |
};
|
|
|
|
| 157 |
|
| 158 |
// ⭐ NEW: realtime update for new messages
|
| 159 |
useEffect(() => {
|
| 160 |
+
let channel, jobsChannel, appsChannel;
|
| 161 |
|
| 162 |
+
const initRealtime = async () => {
|
| 163 |
+
const { data: { user } } = await supabase.auth.getUser();
|
| 164 |
+
if (!user) return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
|
| 166 |
+
channel = supabase
|
| 167 |
+
.channel("messages-badge")
|
| 168 |
+
.on(
|
| 169 |
+
"postgres_changes",
|
| 170 |
+
{ event: "INSERT", schema: "public", table: "messages", filter: `receiver_id=eq.${user.id}` },
|
| 171 |
+
async (payload) => {
|
| 172 |
+
console.log("=== MESSAGES PAYLOAD ===", payload);
|
| 173 |
+
|
| 174 |
+
// Fetch the sender's name from user_roles/companies
|
| 175 |
+
let senderName = 'Admin / HR';
|
| 176 |
+
const { data: roleData } = await supabase
|
| 177 |
+
.from("user_roles")
|
| 178 |
+
.select("name, company_id")
|
| 179 |
+
.eq("user_id", payload.new.sender_id)
|
| 180 |
+
.maybeSingle();
|
| 181 |
|
| 182 |
+
if (roleData) {
|
| 183 |
+
senderName = roleData.name || 'HR';
|
| 184 |
+
if (roleData.company_id) {
|
| 185 |
+
const { data: company } = await supabase.from('companies').select('name').eq('id', roleData.company_id).maybeSingle();
|
| 186 |
+
if (company) senderName = company.name;
|
| 187 |
+
}
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
const newMsg = {
|
| 191 |
+
id: payload.new.id,
|
| 192 |
+
senderName,
|
| 193 |
+
content: payload.new.content,
|
| 194 |
+
timestamp: new Date(payload.new.created_at).toLocaleDateString() + ' • ' + new Date(payload.new.created_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })
|
| 195 |
+
};
|
| 196 |
+
|
| 197 |
+
setUnreadMessagesList(prev => [newMsg, ...prev]);
|
| 198 |
+
setUnreadMessages(prev => prev + 1);
|
| 199 |
+
|
| 200 |
+
// Trigger realtime toast popup
|
| 201 |
+
triggerToast(
|
| 202 |
+
'New Message Received',
|
| 203 |
+
`${senderName} sent you a message`,
|
| 204 |
+
'📨'
|
| 205 |
+
);
|
| 206 |
+
}
|
| 207 |
+
)
|
| 208 |
+
.subscribe();
|
| 209 |
|
| 210 |
const jobsChannel = supabase
|
| 211 |
.channel("jobs-badge")
|
|
|
|
| 315 |
)
|
| 316 |
.subscribe();
|
| 317 |
|
| 318 |
+
};
|
| 319 |
+
|
| 320 |
+
initRealtime();
|
| 321 |
+
|
| 322 |
return () => {
|
| 323 |
+
if (channel) supabase.removeChannel(channel);
|
| 324 |
+
if (jobsChannel) supabase.removeChannel(jobsChannel);
|
| 325 |
+
if (appsChannel) supabase.removeChannel(appsChannel);
|
| 326 |
};
|
| 327 |
|
| 328 |
}, []);
|
src/pages/LoginPage.jsx
CHANGED
|
@@ -170,7 +170,7 @@ export default function LoginPage({ onNavigate }) {
|
|
| 170 |
zIndex: 5,
|
| 171 |
}}>
|
| 172 |
<h1 style={{ fontFamily: "'Orbitron', sans-serif", fontSize: 'clamp(3rem, 10vw, 5rem)', fontWeight: 'bold', marginBottom: '0.5rem', color: 'white' }}>IRIS</h1>
|
| 173 |
-
<p style={{ fontSize: '1.125rem', color: '#a8b2d1' }}>Intelligent
|
| 174 |
</motion.div>
|
| 175 |
|
| 176 |
<div style={{
|
|
|
|
| 170 |
zIndex: 5,
|
| 171 |
}}>
|
| 172 |
<h1 style={{ fontFamily: "'Orbitron', sans-serif", fontSize: 'clamp(3rem, 10vw, 5rem)', fontWeight: 'bold', marginBottom: '0.5rem', color: 'white' }}>IRIS</h1>
|
| 173 |
+
<p style={{ fontSize: '1.125rem', color: '#a8b2d1' }}>Intelligent Recruitment Insight System</p>
|
| 174 |
</motion.div>
|
| 175 |
|
| 176 |
<div style={{
|