173 lines
5.6 KiB
Vue
173 lines
5.6 KiB
Vue
<script setup>
|
|
/**
|
|
* The "add an application" form on `/jobs/`. Rendered only by
|
|
* JobApplications.vue; it creates through stores/jobApplications.js, so the new
|
|
* row appears in the parent's table without the two having to talk.
|
|
*
|
|
* Like JobReferences.vue it reports through the parent's single error banner:
|
|
* `fail` carries the error, `ok` says a create succeeded. `close` asks the
|
|
* parent to fold the form away, which it offers only when `closable`.
|
|
*/
|
|
import { ref } from "vue";
|
|
import { useJobApplicationsStore } from "@/stores/jobApplications";
|
|
import { STATUS_OPTIONS } from "./jobStatus";
|
|
import Icon from "@/components/Icon.vue";
|
|
|
|
defineProps({ closable: { type: Boolean, default: false } });
|
|
const emit = defineEmits(["fail", "ok", "close"]);
|
|
|
|
const store = useJobApplicationsStore();
|
|
|
|
function today() {
|
|
return new Date().toISOString().substring(0, 10);
|
|
}
|
|
|
|
function blankForm() {
|
|
return {
|
|
jobTitle: "",
|
|
company: "",
|
|
location: "",
|
|
url: "",
|
|
status: "applied",
|
|
notes: "",
|
|
salaryRange: "",
|
|
workArrangement: "",
|
|
applicationSource: "",
|
|
resumeVersion: "",
|
|
requisitionId: "",
|
|
contactRole: "",
|
|
// Logging an application on the day you send it is the common case, so the
|
|
// date defaults to today rather than landing null and ageing as unknown.
|
|
appliedAt: today(),
|
|
};
|
|
}
|
|
|
|
const form = ref(blankForm());
|
|
|
|
async function createApplication() {
|
|
if (!form.value.jobTitle.trim() || !form.value.company.trim()) return;
|
|
try {
|
|
await store.create({
|
|
jobTitle: form.value.jobTitle.trim(),
|
|
company: form.value.company.trim(),
|
|
status: form.value.status,
|
|
location: form.value.location || undefined,
|
|
url: form.value.url || undefined,
|
|
notes: form.value.notes || undefined,
|
|
salaryRange: form.value.salaryRange || undefined,
|
|
workArrangement: form.value.workArrangement || undefined,
|
|
applicationSource: form.value.applicationSource || undefined,
|
|
resumeVersion: form.value.resumeVersion || undefined,
|
|
requisitionId: form.value.requisitionId || undefined,
|
|
contactRole: form.value.contactRole || undefined,
|
|
appliedAt: form.value.appliedAt
|
|
? new Date(form.value.appliedAt).toISOString()
|
|
: undefined,
|
|
});
|
|
form.value = blankForm();
|
|
emit("ok");
|
|
} catch (err) {
|
|
// The form is left as typed so the create can be retried.
|
|
emit("fail", err);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<form class="card" @submit.prevent="createApplication">
|
|
<div class="card-header">
|
|
<h2 class="card-title"><Icon name="plus" /> New application</h2>
|
|
<button
|
|
v-if="closable"
|
|
type="button"
|
|
class="btn btn-ghost btn-sm btn-icon"
|
|
title="Close"
|
|
aria-label="Close"
|
|
@click="emit('close')"
|
|
>
|
|
<Icon name="x" />
|
|
</button>
|
|
</div>
|
|
<div class="card-body af-grid">
|
|
<label class="field af-span-2">
|
|
<span>Job title *</span>
|
|
<input v-model="form.jobTitle" class="input" required />
|
|
</label>
|
|
<label class="field af-span-2">
|
|
<span>Company *</span>
|
|
<input v-model="form.company" class="input" required />
|
|
</label>
|
|
<label class="field">
|
|
<span>Status</span>
|
|
<select v-model="form.status" class="input">
|
|
<option v-for="s in STATUS_OPTIONS" :key="s.value" :value="s.value">
|
|
{{ s.label }}
|
|
</option>
|
|
</select>
|
|
</label>
|
|
<label class="field">
|
|
<span>Applied</span>
|
|
<input v-model="form.appliedAt" class="input" type="date" />
|
|
</label>
|
|
<label class="field af-span-2">
|
|
<span>Location</span>
|
|
<input v-model="form.location" class="input" placeholder="e.g. London, hybrid" />
|
|
</label>
|
|
<label class="field af-span-4">
|
|
<span>Posting URL</span>
|
|
<input v-model="form.url" class="input" placeholder="https://" />
|
|
</label>
|
|
<label class="field af-span-6">
|
|
<span>Notes</span>
|
|
<textarea v-model="form.notes" class="input" rows="2" />
|
|
</label>
|
|
<label class="field af-span-2"><span>Salary / range</span><input v-model="form.salaryRange" class="input" placeholder="£60-70k" /></label>
|
|
<label class="field af-span-2"><span>Work arrangement</span><input v-model="form.workArrangement" class="input" placeholder="Hybrid" /></label>
|
|
<label class="field af-span-2"><span>Application source</span><input v-model="form.applicationSource" class="input" placeholder="LinkedIn" /></label>
|
|
<label class="field af-span-2"><span>Resume version</span><input v-model="form.resumeVersion" class="input" placeholder="CV 2026-10" /></label>
|
|
<label class="field af-span-2"><span>Requisition ID</span><input v-model="form.requisitionId" class="input" /></label>
|
|
<label class="field af-span-2"><span>Contact / referral role</span><input v-model="form.contactRole" class="input" placeholder="Hiring manager" /></label>
|
|
<div class="af-actions af-span-6">
|
|
<button v-if="closable" type="button" class="btn" @click="emit('close')">
|
|
Cancel
|
|
</button>
|
|
<button type="submit" class="btn btn-primary">Add application</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</template>
|
|
|
|
<style scoped>
|
|
.af-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(6, minmax(0, 1fr));
|
|
gap: 0.9rem 1rem;
|
|
}
|
|
|
|
.af-span-2 {
|
|
grid-column: span 2;
|
|
}
|
|
.af-span-4 {
|
|
grid-column: span 4;
|
|
}
|
|
.af-span-6 {
|
|
grid-column: 1 / -1;
|
|
}
|
|
|
|
.af-actions {
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
gap: 0.5rem;
|
|
}
|
|
|
|
@media (max-width: 720px) {
|
|
.af-grid {
|
|
grid-template-columns: repeat(2, minmax(0, 1fr));
|
|
}
|
|
.af-span-2,
|
|
.af-span-4 {
|
|
grid-column: 1 / -1;
|
|
}
|
|
}
|
|
</style>
|