diff --git a/src/components/Ausweis/Kundendaten.svelte b/src/components/Ausweis/Kundendaten.svelte new file mode 100644 index 00000000..3797c7db --- /dev/null +++ b/src/components/Ausweis/Kundendaten.svelte @@ -0,0 +1,260 @@ + + +
+
+
+
+

Verbrauchsausweis erstellen - 45€

+ +
+
+ +
+
+
+ +
+
+ +
+ +
+ +
+
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+
+
+ +
+ +
+ +
+ + +
+
+ + +
+ + +
+ + +
+ + +
+ + +
+ + + + + +
+ + +
+ + +
+ + +
+ + +
+ + +
+
+
+ +
+ +
+ +
+
+
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + + + + +
+ + +
+
+
+ +
+ +
+ + +
+
+
+
+
+ + diff --git a/src/components/HelpLabel.svelte b/src/components/HelpLabel.svelte index c68895f9..69fc5c38 100644 --- a/src/components/HelpLabel.svelte +++ b/src/components/HelpLabel.svelte @@ -23,10 +23,10 @@ } .tooltip { - @apply absolute left-0 translate-x-[-50%] max-w-[350px] w-max break-words invisible bg-white rounded-lg p-2 shadow-lg top-0 translate-y-[calc(-100%-8px)]; + @apply absolute left-0 translate-x-[-50%] max-w-[350px] w-max break-words invisible bg-white rounded-lg p-2 shadow-lg top-0 translate-y-[calc(-100%-8px)] transition-all duration-300 opacity-0; } .tooltip-opener:hover .tooltip { - @apply visible; + @apply visible opacity-100; } \ No newline at end of file diff --git a/src/components/ZIPSearch.svelte b/src/components/ZIPSearch.svelte new file mode 100644 index 00000000..377376a8 --- /dev/null +++ b/src/components/ZIPSearch.svelte @@ -0,0 +1,73 @@ + + +
{ + hideZipDropdown = true; +}}> + + { + if (zipCodes.length > 0) { + hideZipDropdown = false + } + }} + maxlength="5" + /> + + +
\ No newline at end of file diff --git a/src/lib/ZIPInformation/index.ts b/src/lib/ZIPInformation/index.ts new file mode 100644 index 00000000..9b3b961d --- /dev/null +++ b/src/lib/ZIPInformation/index.ts @@ -0,0 +1,47 @@ +import { db } from "../shared"; + +type DatabaseZIPInformation = { + zip: string, + city: string, + state: string +}; + +export class ZIPInformation { + public constructor(public zip: string, public city: string, public state: string) { + + } + + public static async fromZipCode(zip: string): Promise { + if (zip.length > 5) { + return null; + } + + let results = await db("zip_codes").select("*").whereLike("zip", `${zip}%`).limit(10); + + if (!results) { + return null; + } + + return results.map(result => new ZIPInformation(result.zip, result.city, result.state)) + } + + public static async fromCity(city: string): Promise { + let results = await db("zip_codes").select("*").where("city", city); + + if (!results) { + return null; + } + + return results.map(result => new ZIPInformation(result.zip, result.city, result.state)) + } + + public static async fromState(state: string): Promise { + let results = await db("zip_codes").select("*").where("state", state); + + if (!results) { + return null; + } + + return results.map(result => new ZIPInformation(result.zip, result.city, result.state)) + } +} \ No newline at end of file diff --git a/src/pages/api/zip.ts b/src/pages/api/zip.ts new file mode 100644 index 00000000..1a739b1f --- /dev/null +++ b/src/pages/api/zip.ts @@ -0,0 +1,28 @@ +import type { APIRoute } from "astro"; +import { success, MissingPropertyError, MissingEntityError, InvalidDataError } from "../../lib/APIResponse"; +import { ZIPInformation } from "src/lib/ZIPInformation"; + +/** + * Ruft einen Nutzer anhand seiner uid aus der Datenbank ab. + * @param param0 Die Request mit dem request body. Dieser enthält entweder eine uid mit der der Benutzer identifiziert werden kann. + */ +export const get: APIRoute = async ({ request }) => { + const body = Object.fromEntries(new URLSearchParams(request.url.split("?")[1])) + + let result; + if (body.zip) { + result = await ZIPInformation.fromZipCode(body.zip) + } else if (body.city) { + result = await ZIPInformation.fromCity(body.city) + } else if (body.state) { + result = await ZIPInformation.fromState(body.state) + } else { + return MissingPropertyError(["Either 'state', 'city' or 'zip' have to exist in request body."]) + } + + if (!result) { + return MissingEntityError("zip info") + } + + return success(result); +} \ No newline at end of file diff --git a/src/pages/verbrauchsausweis/erstellen.astro b/src/pages/verbrauchsausweis/erstellen.astro index bd041097..4631cda8 100644 --- a/src/pages/verbrauchsausweis/erstellen.astro +++ b/src/pages/verbrauchsausweis/erstellen.astro @@ -1,3 +1,7 @@ --- console.log(Object.fromEntries(new URLSearchParams(await Astro.request.text()))) + + + +return Astro.redirect("/verbrauchsausweis/kundendaten"); --- \ No newline at end of file diff --git a/src/pages/verbrauchsausweis/kundendaten.astro b/src/pages/verbrauchsausweis/kundendaten.astro index 6a8032e9..268de1bb 100644 --- a/src/pages/verbrauchsausweis/kundendaten.astro +++ b/src/pages/verbrauchsausweis/kundendaten.astro @@ -1,347 +1,9 @@ --- -import PerformanceScore from "~/components/Ausweis/PerformanceScore.svelte"; -import ProgressBar from "~/components/Ausweis/Progressbar.svelte"; -import HelpLabel from "~/components/HelpLabel.svelte"; +import Kundendaten from "~/components/Ausweis/Kundendaten.svelte"; import AusweisLayout from "~/layouts/AusweisLayout.astro"; --- -
-
-
-
-

Verbrauchsausweis erstellen - 45€

- -
- - -
- -
-
-
- -
-
- -
- -
- -
-
- - -
- -
- -
-
- - -
- -
- -
-
- - -
- -
- -
-
- - -
- -
- -
-
- - -
- -
- -
-
-
-
- -
- -
- -
- - -
-
- -
- -
-
- - -
- -
- -
-
- - -
- -
- -
-
- - -
- -
- -
-
-
- - -
- -
- -
-
- - -
- -
- -
-
- - -
- -
- -
-
-
-
- -
- -
- -
-
-
- - -
- - -
- -
- -
-
- - -
- -
- -
-
- - -
- -
- -
-
- - -
- -
- -
-
-
- - -
- -
- -
-
-
-
- -
- -
- - -
-
-
-
-
+
-