added a test link so the admin can test the interviews too, admin can now go to the landing page too, fixes for the swagger links
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Image from "next/image";
|
||||
import axios from "axios";
|
||||
import AnimatedCounter from "@/components/AnimatedCounter";
|
||||
import FeatureCard from "@/components/FeatureCard";
|
||||
import PricingCard from "@/components/PricingCard";
|
||||
@@ -17,7 +18,27 @@ export default function Home() {
|
||||
// Check if user is already logged in
|
||||
const token = localStorage.getItem("token");
|
||||
if (token) {
|
||||
router.push("/dashboard");
|
||||
// Check if user is admin - if so, allow them to stay on landing page
|
||||
// Non-admin users will be redirected to dashboard
|
||||
axios.get(`${process.env.NEXT_PUBLIC_API_URL}/rest/auth/me`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
const userData = response.data;
|
||||
if (userData.role !== 'admin') {
|
||||
router.push("/dashboard");
|
||||
} else {
|
||||
setIsLoading(false);
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// If token is invalid, remove it and stay on landing page
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("user");
|
||||
setIsLoading(false);
|
||||
});
|
||||
} else {
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
@@ -137,6 +137,42 @@ export default function JobManagement() {
|
||||
setIsAddTokensModalOpen(true);
|
||||
};
|
||||
|
||||
const handleTestInterview = async (job: Job) => {
|
||||
try {
|
||||
const token = localStorage.getItem("token");
|
||||
|
||||
// Get job links for this job
|
||||
const response = await axios.get(`${process.env.NEXT_PUBLIC_API_URL}/rest/admin/jobs/${job.id}/links`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
|
||||
let linkId;
|
||||
if (response.data && response.data.length > 0) {
|
||||
// Use the first available link
|
||||
linkId = response.data[0].url_slug;
|
||||
} else {
|
||||
// Create a test link if none exists
|
||||
const createLinkResponse = await axios.post(`${process.env.NEXT_PUBLIC_API_URL}/rest/admin/jobs/${job.id}/create-link`, {
|
||||
tokensAvailable: 1
|
||||
}, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
});
|
||||
linkId = createLinkResponse.data.url_slug;
|
||||
}
|
||||
|
||||
// Open interview page in test mode with the correct link ID
|
||||
const testUrl = `/interview?id=${linkId}&test=true`;
|
||||
window.open(testUrl, '_blank');
|
||||
} catch (error) {
|
||||
console.error("Failed to get job link for testing:", error);
|
||||
alert("Failed to create test interview link. Please try again.");
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggleJobStatus = async (job: Job) => {
|
||||
try {
|
||||
const token = localStorage.getItem("token");
|
||||
@@ -392,6 +428,12 @@ export default function JobManagement() {
|
||||
>
|
||||
Add Tokens
|
||||
</button>
|
||||
<button
|
||||
onClick={() => handleTestInterview(job)}
|
||||
className="text-purple-600 hover:text-purple-800 dark:text-purple-400 dark:hover:text-purple-300 text-sm font-medium"
|
||||
>
|
||||
Test Interview
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => handleToggleJobStatus(job)}
|
||||
|
||||
Reference in New Issue
Block a user