Update src/app/post-job/page.tsx

This commit is contained in:
2026-03-08 22:24:33 +00:00
parent 00b122afac
commit abf5473f6e

View File

@@ -1,18 +1,19 @@
"use client";
import { useState } from "react";
import { ThemeProvider } from "@/providers/themeProvider/ThemeProvider";
import NavbarStyleCentered from "@/components/navbar/NavbarStyleCentered/NavbarStyleCentered";
import FooterBase from "@/components/sections/footer/FooterBase";
import Input from "@/components/form/Input";
import { Upload, CheckCircle, X } from "lucide-react";
import { useState } from "react";
import { Input } from "@/components/form/Input";
import { Briefcase, Mail, CheckCircle, AlertCircle } from "lucide-react";
import ButtonHoverBubble from "@/components/button/ButtonHoverBubble";
const navItems = [
{ name: "Search Jobs", id: "/search" },
{ name: "Post a Job", id: "/post-job" },
{ name: "Admin", id: "admin-login" },
{ name: "Browse", id: "/browse" },
{ name: "Contact", id: "contact" },
{ name: "Contact", id: "#contact" },
];
const footerColumns = [
@@ -42,29 +43,37 @@ const footerColumns = [
},
];
interface FormData {
jobTitle: string;
companyName: string;
location: string;
jobType: string;
salary: string;
description: string;
requirements: string;
benefits: string;
contactEmail: string;
interface FormErrors {
jobTitle?: string;
company?: string;
location?: string;
salary?: string;
description?: string;
requirements?: string;
email?: string;
}
interface FormErrors {
[key: string]: string;
interface FormData {
jobTitle: string;
company: string;
location: string;
salary: string;
jobType: string;
description: string;
requirements: string;
email: string;
contactPhone?: string;
}
export default function PostJobPage() {
const [formData, setFormData] = useState<FormData>({
jobTitle: "", companyName: "", location: "", jobType: "Full-time", salary: "", description: "", requirements: "", benefits: "", contactEmail: ""});
jobTitle: "", company: "", location: "", salary: "", jobType: "Full-time", description: "", requirements: "", email: "", contactPhone: ""});
const [errors, setErrors] = useState<FormErrors>({});
const [submitted, setSubmitted] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [isSubmitting, setIsSubmitting] = useState(false);
const [submitStatus, setSubmitStatus] = useState<
"idle" | "success" | "error"
>("idle");
const validateForm = (): boolean => {
const newErrors: FormErrors = {};
@@ -72,8 +81,8 @@ export default function PostJobPage() {
if (!formData.jobTitle.trim()) {
newErrors.jobTitle = "Job title is required";
}
if (!formData.companyName.trim()) {
newErrors.companyName = "Company name is required";
if (!formData.company.trim()) {
newErrors.company = "Company name is required";
}
if (!formData.location.trim()) {
newErrors.location = "Location is required";
@@ -81,48 +90,60 @@ export default function PostJobPage() {
if (!formData.salary.trim()) {
newErrors.salary = "Salary range is required";
}
if (!formData.description.trim() || formData.description.trim().length < 20) {
newErrors.description = "Job description must be at least 20 characters";
if (formData.description.trim().length < 20) {
newErrors.description = "Description must be at least 20 characters";
}
if (!formData.requirements.trim() || formData.requirements.trim().length < 20) {
newErrors.requirements = "Requirements must be at least 20 characters";
if (formData.requirements.trim().length < 10) {
newErrors.requirements = "Requirements must be at least 10 characters";
}
if (!formData.contactEmail.trim()) {
newErrors.contactEmail = "Contact email is required";
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.contactEmail)) {
newErrors.contactEmail = "Please enter a valid email address";
if (!formData.email.trim() || !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(formData.email)) {
newErrors.email = "Valid email is required";
}
setErrors(newErrors);
return Object.keys(newErrors).length === 0;
};
const handleInputChange = (field: keyof FormData, value: string) => {
setFormData((prev) => ({ ...prev, [field]: value }));
if (errors[field]) {
setErrors((prev) => {
const newErrors = { ...prev };
delete newErrors[field];
return newErrors;
});
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!validateForm()) {
setSubmitStatus("error");
return;
}
setIsSubmitting(true);
setSubmitStatus("idle");
try {
// Simulate API call
await new Promise((resolve) => setTimeout(resolve, 1500));
setSubmitStatus("success");
setFormData({
jobTitle: "", company: "", location: "", salary: "", jobType: "Full-time", description: "", requirements: "", email: "", contactPhone: ""});
setErrors({});
// Reset success message after 5 seconds
setTimeout(() => setSubmitStatus("idle"), 5000);
} catch (error) {
setSubmitStatus("error");
} finally {
setIsSubmitting(false);
}
};
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
if (!validateForm()) return;
setIsLoading(true);
try {
await new Promise((resolve) => setTimeout(resolve, 2000));
setSubmitted(true);
setFormData({
jobTitle: "", companyName: "", location: "", jobType: "Full-time", salary: "", description: "", requirements: "", benefits: "", contactEmail: ""});
setTimeout(() => setSubmitted(false), 5000);
} catch (error) {
console.error("Submission error:", error);
} finally {
setIsLoading(false);
const handleInputChange = (
e: React.ChangeEvent<
HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement
>
) => {
const { name, value } = e.target;
setFormData((prev) => ({ ...prev, [name]: value }));
if (errors[name as keyof FormErrors]) {
setErrors((prev) => ({
...prev,
[name]: undefined,
}));
}
};
@@ -148,215 +169,251 @@ export default function PostJobPage() {
/>
</div>
<div className="min-h-screen bg-background py-16 md:py-24">
<div className="mx-auto w-full max-w-2xl px-4 md:px-8">
<main className="min-h-screen pt-24 pb-20">
<div className="max-w-2xl mx-auto px-4">
{/* Header */}
<div className="mb-12 text-center">
<h1 className="mb-4 text-4xl md:text-5xl font-bold text-foreground">
Post a Job
<div className="flex items-center justify-center gap-2 mb-4">
<Briefcase className="w-8 h-8" />
<span className="text-sm font-semibold text-primary-cta uppercase tracking-wider">
Post a Job
</span>
</div>
<h1 className="text-4xl md:text-5xl font-bold mb-4">
Hire Top Talent in the Netherlands
</h1>
<p className="text-lg text-foreground/75">
Reach thousands of qualified job seekers across the Netherlands
<p className="text-lg text-foreground/75 max-w-xl mx-auto">
Post your job opening and reach qualified candidates across all Dutch
provinces
</p>
</div>
{/* Success Message */}
{submitted && (
<div className="mb-8 flex items-center gap-3 rounded-lg bg-green-50 p-4 text-green-700 border border-green-200">
<CheckCircle size={20} />
{/* Status Messages */}
{submitStatus === "success" && (
<div className="mb-8 p-4 rounded-lg bg-green-50 border border-green-200 flex items-start gap-3">
<CheckCircle className="w-5 h-5 text-green-600 flex-shrink-0 mt-0.5" />
<div>
<p className="font-semibold">Job posted successfully!</p>
<p className="text-sm">Your job listing will be live shortly.</p>
<h3 className="font-semibold text-green-900">Job Posted Successfully!</h3>
<p className="text-sm text-green-800 mt-1">
Your job listing is now live and visible to job seekers across the
Netherlands.
</p>
</div>
<button
onClick={() => setSubmitted(false)}
className="ml-auto p-1 hover:bg-green-100 rounded"
>
<X size={16} />
</button>
</div>
)}
{/* Form */}
{submitStatus === "error" && Object.keys(errors).length > 0 && (
<div className="mb-8 p-4 rounded-lg bg-red-50 border border-red-200 flex items-start gap-3">
<AlertCircle className="w-5 h-5 text-red-600 flex-shrink-0 mt-0.5" />
<div>
<h3 className="font-semibold text-red-900">Validation Errors</h3>
<p className="text-sm text-red-800 mt-1">
Please correct the errors below and try again.
</p>
</div>
</div>
)}
{/* Job Form */}
<form
onSubmit={handleSubmit}
className="rounded-xl bg-card p-8 md:p-12 border border-accent/20 shadow-lg"
className="space-y-6 bg-card p-8 rounded-2xl border border-background-accent/20 shadow-sm"
>
{/* Job Title */}
<div className="mb-6">
<label className="block mb-2 text-sm font-semibold text-foreground">
Job Title *
<div>
<label htmlFor="jobTitle" className="block text-sm font-semibold mb-2">
Job Title <span className="text-red-500">*</span>
</label>
<Input
value={formData.jobTitle}
onChange={(value) => handleInputChange("jobTitle", value)}
placeholder="e.g., Senior Software Engineer"
onChange={handleInputChange}
name="jobTitle"
placeholder="e.g., Senior React Developer"
required
/>
{errors.jobTitle && (
<p className="mt-1 text-sm text-red-600">{errors.jobTitle}</p>
<p className="text-red-600 text-sm mt-1">{errors.jobTitle}</p>
)}
</div>
{/* Company Name */}
<div className="mb-6">
<label className="block mb-2 text-sm font-semibold text-foreground">
Company Name *
<div>
<label htmlFor="company" className="block text-sm font-semibold mb-2">
Company Name <span className="text-red-500">*</span>
</label>
<Input
value={formData.companyName}
onChange={(value) => handleInputChange("companyName", value)}
value={formData.company}
onChange={handleInputChange}
name="company"
placeholder="Your company name"
required
/>
{errors.companyName && (
<p className="mt-1 text-sm text-red-600">{errors.companyName}</p>
{errors.company && (
<p className="text-red-600 text-sm mt-1">{errors.company}</p>
)}
</div>
{/* Location */}
<div className="mb-6">
<label className="block mb-2 text-sm font-semibold text-foreground">
Location *
</label>
<Input
value={formData.location}
onChange={(value) => handleInputChange("location", value)}
placeholder="e.g., Amsterdam, Netherlands"
required
/>
{errors.location && (
<p className="mt-1 text-sm text-red-600">{errors.location}</p>
)}
</div>
{/* Job Type and Salary */}
<div className="mb-6 grid gap-6 md:grid-cols-2">
{/* Location and Job Type */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label className="block mb-2 text-sm font-semibold text-foreground">
Job Type *
<label htmlFor="location" className="block text-sm font-semibold mb-2">
Location <span className="text-red-500">*</span>
</label>
<Input
value={formData.location}
onChange={handleInputChange}
name="location"
placeholder="e.g., Amsterdam, Remote"
required
/>
{errors.location && (
<p className="text-red-600 text-sm mt-1">{errors.location}</p>
)}
</div>
<div>
<label htmlFor="jobType" className="block text-sm font-semibold mb-2">
Job Type
</label>
<select
name="jobType"
value={formData.jobType}
onChange={(e) => handleInputChange("jobType", e.target.value)}
className="w-full rounded-lg bg-secondary-button px-4 py-2.5 text-foreground placeholder-foreground/75 border border-accent/20 focus:outline-none focus:ring-2 focus:ring-primary-cta"
onChange={handleInputChange}
className="w-full px-4 py-2 rounded-lg bg-secondary-button text-foreground border border-background-accent/20 focus:outline-none focus:ring-2 focus:ring-primary-cta/50"
>
<option>Full-time</option>
<option>Part-time</option>
<option>Contract</option>
<option>Temporary</option>
<option>Internship</option>
<option>Freelance</option>
</select>
</div>
<div>
<label className="block mb-2 text-sm font-semibold text-foreground">
Salary Range *
</label>
<Input
value={formData.salary}
onChange={(value) => handleInputChange("salary", value)}
placeholder="e.g., €50,000 - €80,000"
required
/>
{errors.salary && (
<p className="mt-1 text-sm text-red-600">{errors.salary}</p>
)}
</div>
</div>
{/* Job Description */}
<div className="mb-6">
<label className="block mb-2 text-sm font-semibold text-foreground">
Job Description *
{/* Salary */}
<div>
<label htmlFor="salary" className="block text-sm font-semibold mb-2">
Salary Range <span className="text-red-500">*</span>
</label>
<Input
value={formData.salary}
onChange={handleInputChange}
name="salary"
placeholder="e.g., €50,000 - €70,000"
required
/>
{errors.salary && (
<p className="text-red-600 text-sm mt-1">{errors.salary}</p>
)}
</div>
{/* Description */}
<div>
<label htmlFor="description" className="block text-sm font-semibold mb-2">
Job Description <span className="text-red-500">*</span>
</label>
<textarea
name="description"
value={formData.description}
onChange={(e) => handleInputChange("description", e.target.value)}
placeholder="Describe the role, responsibilities, and key details..."
onChange={handleInputChange}
placeholder="Describe the role, responsibilities, and what makes this opportunity unique..."
rows={6}
className="w-full rounded-lg bg-secondary-button px-4 py-2.5 text-foreground placeholder-foreground/75 border border-accent/20 focus:outline-none focus:ring-2 focus:ring-primary-cta resize-none"
className="w-full px-4 py-3 rounded-lg bg-secondary-button text-foreground placeholder:opacity-75 border border-background-accent/20 focus:outline-none focus:ring-2 focus:ring-primary-cta/50 resize-vertical"
required
/>
{errors.description && (
<p className="mt-1 text-sm text-red-600">{errors.description}</p>
<p className="text-red-600 text-sm mt-1">{errors.description}</p>
)}
</div>
{/* Requirements */}
<div className="mb-6">
<label className="block mb-2 text-sm font-semibold text-foreground">
Requirements *
<div>
<label htmlFor="requirements" className="block text-sm font-semibold mb-2">
Requirements <span className="text-red-500">*</span>
</label>
<textarea
name="requirements"
value={formData.requirements}
onChange={(e) => handleInputChange("requirements", e.target.value)}
placeholder="List the key requirements and qualifications (e.g., skills, experience, education)..."
onChange={handleInputChange}
placeholder="List required skills, experience, and qualifications. One per line recommended."
rows={5}
className="w-full rounded-lg bg-secondary-button px-4 py-2.5 text-foreground placeholder-foreground/75 border border-accent/20 focus:outline-none focus:ring-2 focus:ring-primary-cta resize-none"
className="w-full px-4 py-3 rounded-lg bg-secondary-button text-foreground placeholder:opacity-75 border border-background-accent/20 focus:outline-none focus:ring-2 focus:ring-primary-cta/50 resize-vertical"
required
/>
{errors.requirements && (
<p className="mt-1 text-sm text-red-600">{errors.requirements}</p>
<p className="text-red-600 text-sm mt-1">{errors.requirements}</p>
)}
</div>
{/* Benefits */}
<div className="mb-6">
<label className="block mb-2 text-sm font-semibold text-foreground">
Benefits (Optional)
</label>
<textarea
value={formData.benefits}
onChange={(e) => handleInputChange("benefits", e.target.value)}
placeholder="Highlight benefits such as remote work, flexible hours, health insurance, training, etc."
rows={4}
className="w-full rounded-lg bg-secondary-button px-4 py-2.5 text-foreground placeholder-foreground/75 border border-accent/20 focus:outline-none focus:ring-2 focus:ring-primary-cta resize-none"
/>
</div>
{/* Contact Email */}
<div className="mb-8">
<label className="block mb-2 text-sm font-semibold text-foreground">
Contact Email *
</label>
<Input
value={formData.contactEmail}
onChange={(value) => handleInputChange("contactEmail", value)}
type="email"
placeholder="your-email@company.com"
required
/>
{errors.contactEmail && (
<p className="mt-1 text-sm text-red-600">{errors.contactEmail}</p>
)}
{/* Contact Information */}
<div className="border-t border-background-accent/20 pt-6">
<h3 className="text-lg font-semibold mb-4">Contact Information</h3>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label htmlFor="email" className="block text-sm font-semibold mb-2">
Email Address <span className="text-red-500">*</span>
</label>
<Input
value={formData.email}
onChange={handleInputChange}
name="email"
type="email"
placeholder="recruiter@company.com"
required
/>
{errors.email && (
<p className="text-red-600 text-sm mt-1">{errors.email}</p>
)}
</div>
<div>
<label htmlFor="contactPhone" className="block text-sm font-semibold mb-2">
Phone Number (Optional)
</label>
<Input
value={formData.contactPhone}
onChange={handleInputChange}
name="contactPhone"
type="tel"
placeholder="+31 (0)6 1234 5678"
/>
</div>
</div>
</div>
{/* Submit Button */}
<button
type="submit"
disabled={isLoading}
className="w-full rounded-lg bg-primary-cta px-6 py-3 font-semibold text-white hover:opacity-90 disabled:opacity-50 disabled:cursor-not-allowed transition-opacity flex items-center justify-center gap-2"
>
{isLoading ? (
<>
<div className="h-5 w-5 animate-spin rounded-full border-2 border-white border-t-transparent"></div>
Posting...
</>
) : (
<>
<Upload size={18} />
Post Job
</>
)}
</button>
{/* Form Info */}
<p className="mt-4 text-center text-sm text-foreground/60">
* Required fields. Your job will be reviewed before going live.
</p>
<div className="flex gap-4 pt-4">
<button
type="submit"
disabled={isSubmitting}
className="flex-1 px-6 py-3 rounded-lg bg-primary-cta text-white font-semibold disabled:opacity-60 disabled:cursor-not-allowed transition-opacity"
>
{isSubmitting ? "Posting Job..." : "Post Job"}
</button>
<button
type="button"
onClick={() => window.history.back()}
className="px-6 py-3 rounded-lg bg-secondary-button text-foreground font-semibold hover:bg-background-accent/20 transition-colors"
>
Cancel
</button>
</div>
</form>
{/* Info Section */}
<div className="mt-12 grid grid-cols-1 md:grid-cols-3 gap-6">
<div className="text-center">
<div className="text-3xl font-bold text-primary-cta mb-2">100%</div>
<p className="text-foreground/75">of jobs posted are visible immediately</p>
</div>
<div className="text-center">
<div className="text-3xl font-bold text-primary-cta mb-2">24/7</div>
<p className="text-foreground/75">job listings stay live around the clock</p>
</div>
<div className="text-center">
<div className="text-3xl font-bold text-primary-cta mb-2">All NL</div>
<p className="text-foreground/75">reach candidates across Netherlands</p>
</div>
</div>
</div>
</div>
</main>
<div id="footer" data-section="footer">
<FooterBase