web: fix dates on website

This commit is contained in:
Mika 2024-07-11 15:05:18 +02:00
parent 7103636ed6
commit 8f9eb24c23
5 changed files with 108 additions and 117 deletions

View file

@ -5,9 +5,9 @@
<ListViewElement <ListViewElement
:licenseName="license.name" :licenseName="license.name"
:licenseKey="license.key" :licenseKey="license.key"
startDate="license.start" :startDate="license.start ? new Date(license.start) : null"
endDate="license.end" :endDate="license.end ? new Date(license.end) : null"
:amount=license.amount :amount="license.amount"
notes="license.notes" notes="license.notes"
/> />
</li> </li>
@ -21,32 +21,21 @@
notes="" notes=""
/> --> /> -->
</div> </div>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import ListViewElement from './ListViewElement.vue' import ListViewElement from "./ListViewElement.vue";
import { License } from "@/types";
interface License {
name: string;
id: string;
start?: Date,
end?: Date,
key: string,
amount?: number,
}
const props = defineProps<{ licenseGroupName: string, licenses: License[]}>()
const props = defineProps<{ licenseGroupName: string; licenses: License[] }>();
</script> </script>
<style scoped> <style scoped>
.root { .root {
margin-top: 10px; margin-top: 10px;
} }
li { li {
list-style-type: none; list-style-type: none;
} }
</style> </style>

View file

@ -13,7 +13,7 @@
</v-btn> </v-btn>
<v-dialog v-model="group" width="600" persistent> <v-dialog v-model="group" width="600" persistent>
<v-card max-width="600"> <v-card max-width="600">
<v-form @submit.prevent="submit"> <v-form @submit.prevent="submitGroup">
<v-card-title> <v-card-title>
<span class="headline">Add Group</span> <span class="headline">Add Group</span>
</v-card-title> </v-card-title>
@ -24,7 +24,7 @@
<div> <div>
<v-text-field <v-text-field
label="Group Name *" label="Group Name *"
v-model="groupLicenseName" v-model="groupGroupName"
variant="outlined" variant="outlined"
required required
clearable clearable
@ -189,25 +189,17 @@
import { store } from "@/store"; import { store } from "@/store";
import { SubmitEventPromise } from "vuetify"; import { SubmitEventPromise } from "vuetify";
import { ref } from "vue"; import { ref } from "vue";
import { Plus, LogOut, Pencil, FolderPlus } from "lucide-vue-next"; import { Plus, LogOut, FolderPlus } from "lucide-vue-next";
import { useQuery, useMutation, useQueryClient } from "@tanstack/vue-query"; import { useQuery, useMutation, useQueryClient } from "@tanstack/vue-query";
import axios from "axios";
import { axiosInstance } from "@/client"; import { axiosInstance } from "@/client";
import { LicenseGroup, CreateLicenseDto } from "@/types"; import { LicenseGroup, CreateLicenseDto, CreateGroupDto } from "@/types";
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const { data } = useQuery({ const { data } = useQuery({
queryKey: ["licenses"], queryKey: ["licenses"],
queryFn: async () => { queryFn: async () => {
const res = await axios.get<LicenseGroup[]>( const res = await axiosInstance.get<LicenseGroup[]>("/licenses");
import.meta.env.VITE_BACKEND_URL + "/licenses",
{
headers: {
Authorization: `Bearer ${store.token}`,
},
}
);
return res.data; return res.data;
}, },
select: (data) => { select: (data) => {
@ -220,7 +212,7 @@ const { data } = useQuery({
}, },
}); });
const { isPending, mutate } = useMutation({ const { mutate: licenseMutate } = useMutation({
mutationFn: async (newLicense: CreateLicenseDto) => { mutationFn: async (newLicense: CreateLicenseDto) => {
await axiosInstance.post("/licenses", newLicense); await axiosInstance.post("/licenses", newLicense);
}, },
@ -233,6 +225,19 @@ const { isPending, mutate } = useMutation({
}, },
}); });
const { mutate: groupsMutate } = useMutation({
mutationFn: async (newGroup: CreateGroupDto) => {
await axiosInstance.post("/groups", newGroup);
},
onError: (error) => {
snackbar.value = true;
},
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["licenses"] });
group.value = false;
},
});
function handlelogout() { function handlelogout() {
store.setToken(null); store.setToken(null);
} }
@ -245,12 +250,25 @@ async function submit(event: SubmitEventPromise) {
group_id: addLicenseGroup.value, group_id: addLicenseGroup.value,
amount: addAmount.value, amount: addAmount.value,
key: addLicenseKey.value, key: addLicenseKey.value,
start: addStartDate.value, start: addStartDate.value ?? null,
stop: addStopDate.value, end: addStopDate.value ?? null,
notes: addNotes.value, notes: addNotes.value,
}; };
console.log(data); console.log(data);
mutate(data); licenseMutate(data);
} else {
console.log("Invalid");
}
}
async function submitGroup(event: SubmitEventPromise) {
const result = await event;
if (result.valid) {
const groupsData = {
name: groupGroupName.value,
};
console.log(groupsData);
groupsMutate(groupsData);
} else { } else {
console.log("Invalid"); console.log("Invalid");
} }
@ -263,7 +281,7 @@ const snackbar = ref(false);
// //
const group = ref(false); // Dialog for Group const group = ref(false); // Dialog for Group
const groupLicenseName = ref<string>(""); const groupGroupName = ref<string>("");
// Rules for Group Dialog // Rules for Group Dialog
const licenseGroupRules = [ const licenseGroupRules = [
@ -312,12 +330,6 @@ const addNotes = ref<string | undefined>("");
// Date Picker // Date Picker
const addStartDate = ref<Date | undefined>(); const addStartDate = ref<Date | undefined>();
const addStopDate = ref<Date | undefined>(); const addStopDate = ref<Date | undefined>();
//
// EDIT SECTION
//
const edit = ref(false);
</script> </script>
<style scoped> <style scoped>

View file

@ -1,10 +1,5 @@
<template> <template>
<v-sheet <v-sheet elevation="4" width="96vw" rounded="lg" class="mt-3">
elevation="4"
width="96vw"
rounded="lg"
class="mt-3"
>
<v-expansion-panels> <v-expansion-panels>
<v-expansion-panel> <v-expansion-panel>
<v-expansion-panel-title> <v-expansion-panel-title>
@ -25,17 +20,12 @@
style="align-items: center" style="align-items: center"
> >
<CalendarCheck /> <CalendarCheck />
<span <span>
v-if=" {{
props.startDate == null || props.startDate
props.startDate == undefined || ? props.startDate.toLocaleDateString()
props.startDate.length == 0 : "Verfügbar"
" }}
>
Verfügbar
</span>
<span v-else>
{{ props.startDate }}
</span> </span>
</div> </div>
@ -44,17 +34,12 @@
style="align-items: center" style="align-items: center"
> >
<CalendarX /> <CalendarX />
<span <span>
v-if=" {{
props.endDate == null || props.endDate
props.endDate == undefined || ? props.endDate.toLocaleDateString()
props.endDate.length == 0 : "Ewig Verfügbar"
" }}
>
Ewig Verfügbar
</span>
<span v-else>
{{ props.endDate }}
</span> </span>
</div> </div>
@ -78,38 +63,33 @@
</v-expansion-panel-title> </v-expansion-panel-title>
<v-expansion-panel-text> <v-expansion-panel-text>
Notes: Notes:
<v-row <v-row class="flex-nowrap" no-gutters>
class="flex-nowrap" <v-col
no-gutters class="flex-grow-1 flex-shrink-0 overflow-x-auto border-e-md"
cols="10"
> >
<v-col {{ props.notes }}
class="flex-grow-1 align-self-end overflow-x-auto border-e-md" </v-col>
cols="10"
>
{{ props.notes }}
</v-col>
<v-col
class=""
cols="2"
align="end"
>
<!-- -->
<!-- EDIT SECTION -->
<!-- -->
<v-btn class="mr-3" flat size="small">
<Pencil />
</v-btn>
<!-- -->
<!-- DELETE BTN -->
<!-- -->
<v-btn class="mr-3" flat size="small" color="red" variant="text">
<Trash />
</v-btn>
</v-col>
</v-row>
<v-col
class="flex-grow-0 flex-shrink-1 overflow-x-auto"
cols="2"
align="end"
>
<!-- -->
<!-- EDIT SECTION -->
<!-- -->
<v-btn class="mr-3" flat size="small">
<Pencil />
</v-btn>
<!-- -->
<!-- DELETE BTN -->
<!-- -->
<v-btn class="mr-3" flat size="small" color="red" variant="text">
<Trash />
</v-btn>
</v-col>
</v-row>
</v-expansion-panel-text> </v-expansion-panel-text>
</v-expansion-panel> </v-expansion-panel>
</v-expansion-panels> </v-expansion-panels>
@ -117,18 +97,25 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { Infinity, KeyRound, CalendarCheck, CalendarX, Pencil, Trash } from "lucide-vue-next"; import {
Infinity,
KeyRound,
CalendarCheck,
CalendarX,
Pencil,
Trash,
Power,
} from "lucide-vue-next";
import { ref } from "vue"; import { ref } from "vue";
const props = defineProps({ const props = defineProps<{
licenseName: String, licenseName: string;
licenseKey: String, licenseKey: string;
startDate: String, startDate: Date | null;
endDate: String, endDate: Date | null;
amount: Number, amount?: number;
notes: String, notes?: string;
}); }>();
// //
// EDIT SECTION // EDIT SECTION
// //

View file

@ -27,6 +27,7 @@ const { isPending, isError, data, error } = useQuery({
queryKey: ["licenses"], queryKey: ["licenses"],
queryFn: async () => { queryFn: async () => {
const res = await axiosInstance.get<LicenseGroup[]>("/licenses"); const res = await axiosInstance.get<LicenseGroup[]>("/licenses");
console.log(res.data);
return res.data; return res.data;
}, },
}); });

View file

@ -7,10 +7,12 @@ export interface LicenseGroup {
export interface License { export interface License {
name: string; name: string;
id: string; id: string;
start?: Date; start?: string;
end?: Date; end?: string;
key: string; key: string;
amount?: number; amount?: number;
} }
export type CreateLicenseDto = Omit<License, "id"> & { group_id: string }; export type CreateLicenseDto = Omit<License, "id"> & { group_id: string };
export type CreateGroupDto = Omit<LicenseGroup, "id" | "licenses">;