web: refactor add license

Co-authored-by: Schmackofatz <Schmackofatz@gmail.com>
This commit is contained in:
Mika 2024-07-11 12:19:35 +02:00
parent b1f2f6507e
commit ad7b0f0732
3 changed files with 120 additions and 41 deletions

View file

@ -76,8 +76,31 @@
:rules="licenseNameRules" :rules="licenseNameRules"
class="mb-3" class="mb-3"
></v-text-field> ></v-text-field>
<v-text-field
label="License Key *"
v-model="addLicenseKey"
variant="outlined"
required
clearable
:rules="licenseKeyRules"
class="mb-3"
></v-text-field>
<v-autocomplete
clearable
label="Select Group *"
:items="data"
variant="outlined"
:rules="selectGroupRules"
class="mb-1"
v-model="addLicenseGroup"
></v-autocomplete>
<!-- Divider maybe remove -->
<v-divider
class="border-opacity-50"
:thickness="2"
></v-divider>
<div> <div>
<div class="mb-3"> <div class="mb-3 mt-3">
<v-date-input <v-date-input
label="Start Date (optional)" label="Start Date (optional)"
variant="outlined" variant="outlined"
@ -85,9 +108,10 @@
prepend-inner-icon="mdi-calendar-check" prepend-inner-icon="mdi-calendar-check"
clearable clearable
v-model="addStartDate" v-model="addStartDate"
hide-details
></v-date-input> ></v-date-input>
</div> </div>
<div class="mb-5"> <div class="mb-6">
<v-date-input <v-date-input
label="Stop Date (optional)" label="Stop Date (optional)"
variant="outlined" variant="outlined"
@ -95,6 +119,7 @@
prepend-inner-icon="mdi-calendar-remove" prepend-inner-icon="mdi-calendar-remove"
clearable clearable
v-model="addStopDate" v-model="addStopDate"
hide-details
></v-date-input> ></v-date-input>
</div> </div>
</div> </div>
@ -112,19 +137,6 @@
variant="outlined" variant="outlined"
clearable clearable
></v-text-field> ></v-text-field>
<v-select
clearable
label="Select Group *"
:items="[
'California',
'Colorado',
'Florida',
'Georgia',
'Texas',
'Wyoming',
]"
variant="outlined"
></v-select>
<span class="dialogNote"> <span class="dialogNote">
all fields marked with * are required all fields marked with * are required
</span> </span>
@ -210,6 +222,32 @@ 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, Pencil, FolderPlus } from "lucide-vue-next";
import { useQuery } from "@tanstack/vue-query";
import axios from "axios";
import { LicenseGroup } from "@/types";
const { data } = useQuery({
queryKey: ["licenses"],
queryFn: async () => {
const res = await axios.get<LicenseGroup[]>(
import.meta.env.VITE_BACKEND_URL + "/licenses",
{
headers: {
Authorization: `Bearer ${store.token}`,
},
}
);
return res.data;
},
select: (data) => {
return data.map((group) => {
return {
title: group.name,
value: group.id,
};
});
},
});
function handlelogout() { function handlelogout() {
store.setToken(null); store.setToken(null);
@ -217,8 +255,21 @@ function handlelogout() {
async function submit(event: SubmitEventPromise) { async function submit(event: SubmitEventPromise) {
const result = await event; const result = await event;
console.log(result); if (result.valid) {
console.log({
name: addLicenseName.value,
group_id: addLicenseGroup.value,
amount: addAmount.value,
key: addLicenseKey.value,
start: addStartDate.value,
stop: addStopDate.value,
notes: addNotes.value,
});
} else {
console.log("Invalid");
}
} }
// //
// GROUP SECTION // GROUP SECTION
// //
@ -226,6 +277,7 @@ async function submit(event: SubmitEventPromise) {
const group = ref(false); // Dialog for Group const group = ref(false); // Dialog for Group
const groupLicenseName = ref<string>(""); const groupLicenseName = ref<string>("");
// Rules for Group Dialog
const licenseGroupRules = [ const licenseGroupRules = [
(value: string) => { (value: string) => {
if (value) return true; if (value) return true;
@ -239,6 +291,10 @@ const licenseGroupRules = [
const add = ref(false); const add = ref(false);
// References for Add License Dialog // References for Add License Dialog
const addLicenseName = ref<string>(""); const addLicenseName = ref<string>("");
const addLicenseKey = ref<string>("");
const addLicenseGroup = ref<string>();
// Rules for Add License Dialog
const licenseNameRules = [ const licenseNameRules = [
(value: string) => { (value: string) => {
if (value) return true; if (value) return true;
@ -246,6 +302,22 @@ const licenseNameRules = [
return "YOU MUST ENTER (A LICENSE NAME)"; return "YOU MUST ENTER (A LICENSE NAME)";
}, },
]; ];
const selectGroupRules = [
(value: string) => {
if (value) return true;
return "YOU MUST SELECT (A LICENSE GROUP)";
},
];
const licenseKeyRules = [
(value: string) => {
if (value) return true;
return "YOU MUST ENTER (A LICENSE KEY)";
},
];
// Optional Fields
const addAmount = ref<number | undefined>(); const addAmount = ref<number | undefined>();
const addNotes = ref<string | undefined>(""); const addNotes = ref<string | undefined>("");

View file

@ -6,7 +6,10 @@
<div v-else-if="isError">Error: {{ error?.message }}</div> <div v-else-if="isError">Error: {{ error?.message }}</div>
<ul v-else-if="data"> <ul v-else-if="data">
<li v-for="group in data" :key="group.id"> <li v-for="group in data" :key="group.id">
<CategoryContainer :licenseGroupName="group.name" :licenses="group.licenses" /> <CategoryContainer
:licenseGroupName="group.name"
:licenses="group.licenses"
/>
</li> </li>
</ul> </ul>
</div> </div>
@ -19,37 +22,27 @@ import CategoryContainer from "./CategoryContainer.vue";
import { useQuery } from "@tanstack/vue-query"; import { useQuery } from "@tanstack/vue-query";
import axios from "axios"; import axios from "axios";
import { store } from "@/store"; import { store } from "@/store";
import { LicenseGroup } from "@/types";
interface LicenseGroup { const { isPending, isError, data, error } = useQuery({
id: string,
name: string,
licenses: License[]
}
interface License {
name: string;
id: string;
start?: Date,
end?: Date,
key: string,
amount?: number,
}
const {isPending, isError, data, error} = useQuery({
queryKey: ["licenses"], queryKey: ["licenses"],
queryFn: async () => { queryFn: async () => {
const res = await axios.get<LicenseGroup[]>(import.meta.env.VITE_BACKEND_URL + "/licenses", { const res = await axios.get<LicenseGroup[]>(
headers: { import.meta.env.VITE_BACKEND_URL + "/licenses",
Authorization: `Bearer ${store.token}` {
headers: {
Authorization: `Bearer ${store.token}`,
},
} }
}) );
return res.data return res.data;
} },
}) });
</script> </script>
<style scoped> <style scoped>
li, ul { li,
ul {
list-style-type: none; list-style-type: none;
} }
</style> </style>

14
web/src/types.ts Normal file
View file

@ -0,0 +1,14 @@
export interface LicenseGroup {
id: string;
name: string;
licenses: License[];
}
export interface License {
name: string;
id: string;
start?: Date;
end?: Date;
key: string;
amount?: number;
}