diff --git a/package.json b/package.json index 7c22884..85f5e76 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "type": "module", "scripts": { - "dev": "vite", + "dev": "vite --force", "build": "run-p type-check \"build-only {@}\" --", "preview": "vite preview", "test:unit": "vitest --typecheck", diff --git a/src/components/generic/PersonalInformation.vue b/src/components/generic/PersonalInformation.vue index 3dc89b1..ddd62da 100644 --- a/src/components/generic/PersonalInformation.vue +++ b/src/components/generic/PersonalInformation.vue @@ -3,42 +3,60 @@ import { ApplicationTestId } from "@/util/enums"; import { ref } from "vue"; import { storeToRefs } from "pinia"; import { useAuthStore } from "@/stores/auth"; -const { token } = storeToRefs(useAuthStore()); -const props = defineProps<{ - basePath: string; -}>(); +const { token, role } = storeToRefs(useAuthStore()); +const props = defineProps({ + basePath: { + type: String, + required: true + }, + personId: Number +}); const personalInformationPath = props.basePath + "personal-information."; const { firstNameInput, lastNameInput, personNumberInput, emailInput } = initPersonalInformation(); +getPersonalInformation(); + function initPersonalInformation() { return { - firstNameInput: ref("Sven"), - lastNameInput: ref("Svensson"), - personNumberInput: ref("930101-xxxx"), - emailInput: ref("test@exempel.com") + firstNameInput: ref(""), + lastNameInput: ref(""), + personNumberInput: ref(""), + emailInput: ref("") }; } -fetch("https://application-form-service-8e764787209b.herokuapp.com/api/application-form/applicant/personal-info/", { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${token.value}` - } -}).then((response) => { - if (response.status !== 200) { - throw "could not get personal information, status code: " + response.status; - } else { - response.json().then((result) => { - firstNameInput.value = result.name; - lastNameInput.value = result.surname; - personNumberInput.value = result.pnr; - emailInput.value = result.email; - }); +function getPersonalInformation() { + let params: "" | number = ""; + + if (props.personId && role.value === "Recruiter") { + params = props.personId; } -}); + + const url = + "https://personal-info-service-f25ca556a7c9.herokuapp.com/api/application-form/applicant/personal-info/" + params; + let options = { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${token.value}` + } + }; + + fetch(url, options).then((response) => { + if (response.status !== 200) { + throw "could not get personal information, status code: " + response.status; + } else { + response.json().then((result) => { + firstNameInput.value = result.name; + lastNameInput.value = result.surname; + personNumberInput.value = result.pnr; + emailInput.value = result.email; + }); + } + }); +}