From bfeca6e8e03b7c21bf73af741cdadd2bcbf1b10c Mon Sep 17 00:00:00 2001
From: Reto Aebersold
Date: Mon, 13 Nov 2023 20:58:21 +0100
Subject: [PATCH] feat: use orgs in profile
---
client/src/fetchHelpers.ts | 23 ++++++++++
.../src/pages/onboarding/AccountProfile.vue | 15 +++++--
client/src/pages/onboarding/companies.ts | 34 --------------
server/config/urls.py | 2 +-
.../core/migrations/0003_user_organisation.py | 45 ++++++++++++++++---
5 files changed, 76 insertions(+), 43 deletions(-)
delete mode 100644 client/src/pages/onboarding/companies.ts
diff --git a/client/src/fetchHelpers.ts b/client/src/fetchHelpers.ts
index f9a4d699..af1a14e4 100644
--- a/client/src/fetchHelpers.ts
+++ b/client/src/fetchHelpers.ts
@@ -1,4 +1,6 @@
import { getCookieValue } from "@/router/guards";
+import type { Ref } from "vue";
+import { ref, toValue, watchEffect } from "vue";
class FetchError extends Error {
response: Response;
@@ -88,3 +90,24 @@ export const itGetCached = (
return itGetPromiseCache.get(url.toString()) as Promise;
};
+
+export function useFetch(url: Ref | RequestInfo | (() => RequestInfo)) {
+ const data = ref(null);
+ const error = ref(null);
+
+ const fetchData = () => {
+ data.value = null;
+ error.value = null;
+
+ fetch(toValue(url))
+ .then((res) => res.json())
+ .then((json) => (data.value = json))
+ .catch((err) => (error.value = err));
+ };
+
+ watchEffect(() => {
+ fetchData();
+ });
+
+ return { data, error };
+}
diff --git a/client/src/pages/onboarding/AccountProfile.vue b/client/src/pages/onboarding/AccountProfile.vue
index 3091ab1d..ad221468 100644
--- a/client/src/pages/onboarding/AccountProfile.vue
+++ b/client/src/pages/onboarding/AccountProfile.vue
@@ -5,12 +5,21 @@ import { computed, ref, watch } from "vue";
import { useUserStore } from "@/stores/user";
import AvatarImage from "@/components/ui/AvatarImage.vue";
import { useFileUpload } from "@/composables";
-import { companies } from "@/pages/onboarding/companies";
import { useRoute } from "vue-router";
+import { useFetch } from "@/fetchHelpers";
+import { useTranslation } from "i18next-vue";
+
+const { t } = useTranslation();
const user = useUserStore();
const route = useRoute();
-const selectedCompany = ref(companies[0]);
+
+const { data: companies } = useFetch(() => "/api/core/organisations/");
+
+const selectedCompany = ref({
+ id: "0",
+ name: t("a.Auswählen"),
+});
const validCompany = computed(() => {
return selectedCompany.value.id !== "0";
});
@@ -53,7 +62,7 @@ const nextRoute = computed(() => {
andere Personen einfacher finden.
-
diff --git a/client/src/pages/onboarding/companies.ts b/client/src/pages/onboarding/companies.ts
deleted file mode 100644
index 92edfd64..00000000
--- a/client/src/pages/onboarding/companies.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-export const companies = [
- { id: "0", name: "Auswählen" },
- { id: "1", name: "Andere Broker" },
- { id: "2", name: "Andere Krankenversicherer" },
- { id: "3", name: "Andere Privatversicherer" },
- { id: "4", name: "Allianz Suisse" },
- { id: "5", name: "AON" },
- { id: "6", name: "AXA Winterthur" },
- { id: "7", name: "Baloise" },
- { id: "8", name: "CAP Rechtsschutz" },
- { id: "9", name: "Coop Rechtsschutz" },
- { id: "10", name: "CSS" },
- { id: "11", name: "Die Mobiliar" },
- { id: "12", name: "Emmental Versicherung" },
- { id: "13", name: "GENERALI Versicherungen" },
- { id: "14", name: "Groupe Mutuel" },
- { id: "15", name: "Helsana" },
- { id: "16", name: "Helvetia" },
- { id: "17", name: "Kessler & Co AG" },
- { id: "18", name: "Orion Rechtsschutz Versicherung" },
- { id: "19", name: "PAX" },
- { id: "20", name: "Sanitas" },
- { id: "21", name: "SUVA" },
- { id: "22", name: "Swica" },
- { id: "23", name: "Swiss Life" },
- { id: "24", name: "Swiss Re" },
- { id: "25", name: "Visana Services AG" },
- { id: "26", name: "VZ VermögensZentrum AG" },
- { id: "27", name: "Würth Financial Services AG" },
- { id: "28", name: "Zürich" },
- { id: "29", name: "VBV" },
- { id: "30", name: "Vaudoise" },
- { id: "31", name: "Keine Firmenzugehörigkeit" },
-];
diff --git a/server/config/urls.py b/server/config/urls.py
index da7ff21d..3d6b1e32 100644
--- a/server/config/urls.py
+++ b/server/config/urls.py
@@ -20,13 +20,13 @@ from vbv_lernwelt.core.views import (
check_rate_limit,
cypress_reset_view,
generate_web_component_icons,
+ list_organisations,
me_user_view,
permission_denied_view,
rate_limit_exceeded_view,
vue_home,
vue_login,
vue_logout,
- list_organisations,
)
from vbv_lernwelt.course.views import (
course_page_api_view,
diff --git a/server/vbv_lernwelt/core/migrations/0003_user_organisation.py b/server/vbv_lernwelt/core/migrations/0003_user_organisation.py
index cb5f02d7..fdf3922c 100644
--- a/server/vbv_lernwelt/core/migrations/0003_user_organisation.py
+++ b/server/vbv_lernwelt/core/migrations/0003_user_organisation.py
@@ -4,15 +4,50 @@ from django.db import migrations, models
class Migration(migrations.Migration):
-
dependencies = [
- ('core', '0002_joblog'),
+ ("core", "0002_joblog"),
]
operations = [
migrations.AddField(
- model_name='user',
- name='organisation',
- field=models.CharField(blank=True, choices=[('1', 'Andere Broker'), ('2', 'Andere Krankenversicherer'), ('3', 'Andere Privatversicherer'), ('4', 'Allianz Suisse'), ('5', 'AON'), ('6', 'AXA Winterthur'), ('7', 'Baloise'), ('8', 'CAP Rechtsschutz'), ('9', 'Coop Rechtsschutz'), ('10', 'CSS'), ('11', 'Die Mobiliar'), ('12', 'Emmental Versicherung'), ('13', 'GENERALI Versicherungen'), ('14', 'Groupe Mutuel'), ('15', 'Helsana'), ('16', 'Helvetia'), ('17', 'Kessler & Co AG'), ('18', 'Orion Rechtsschutz Versicherung'), ('19', 'PAX'), ('20', 'Sanitas'), ('21', 'SUVA'), ('22', 'Swica'), ('23', 'Swiss Life'), ('24', 'Swiss Re'), ('25', 'Visana Services AG'), ('26', 'VZ VermögensZentrum AG'), ('27', 'Würth Financial Services AG'), ('28', 'Zürich'), ('29', 'VBV'), ('30', 'Vaudoise'), ('31', 'Keine Firmenzugehörigkeit')], max_length=255),
+ model_name="user",
+ name="organisation",
+ field=models.CharField(
+ blank=True,
+ choices=[
+ ("1", "Andere Broker"),
+ ("2", "Andere Krankenversicherer"),
+ ("3", "Andere Privatversicherer"),
+ ("4", "Allianz Suisse"),
+ ("5", "AON"),
+ ("6", "AXA Winterthur"),
+ ("7", "Baloise"),
+ ("8", "CAP Rechtsschutz"),
+ ("9", "Coop Rechtsschutz"),
+ ("10", "CSS"),
+ ("11", "Die Mobiliar"),
+ ("12", "Emmental Versicherung"),
+ ("13", "GENERALI Versicherungen"),
+ ("14", "Groupe Mutuel"),
+ ("15", "Helsana"),
+ ("16", "Helvetia"),
+ ("17", "Kessler & Co AG"),
+ ("18", "Orion Rechtsschutz Versicherung"),
+ ("19", "PAX"),
+ ("20", "Sanitas"),
+ ("21", "SUVA"),
+ ("22", "Swica"),
+ ("23", "Swiss Life"),
+ ("24", "Swiss Re"),
+ ("25", "Visana Services AG"),
+ ("26", "VZ VermögensZentrum AG"),
+ ("27", "Würth Financial Services AG"),
+ ("28", "Zürich"),
+ ("29", "VBV"),
+ ("30", "Vaudoise"),
+ ("31", "Keine Firmenzugehörigkeit"),
+ ],
+ max_length=255,
+ ),
),
]