web: add support for adding a license
This commit is contained in:
parent
768b36da56
commit
77abeb558e
4 changed files with 43 additions and 15 deletions
11
web/src/client.ts
Normal file
11
web/src/client.ts
Normal file
|
@ -0,0 +1,11 @@
|
|||
import axios from "axios";
|
||||
import { store } from "@/store";
|
||||
let axiosInstance = axios.create({
|
||||
baseURL: import.meta.env.VITE_BACKEND_URL,
|
||||
});
|
||||
axiosInstance.interceptors.request.use((config) => {
|
||||
config.headers.Authorization = `Bearer ${store.token}`;
|
||||
return config;
|
||||
});
|
||||
|
||||
export { axiosInstance };
|
|
@ -215,6 +215,9 @@
|
|||
</v-btn>
|
||||
</v-toolbar>
|
||||
</div>
|
||||
<v-snackbar v-model="snackbar" :timeout="2000" elevation="24" location="top">
|
||||
<span> Who am I??? </span>
|
||||
</v-snackbar>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
@ -222,9 +225,12 @@ import { store } from "@/store";
|
|||
import { SubmitEventPromise } from "vuetify";
|
||||
import { ref } from "vue";
|
||||
import { Plus, LogOut, Pencil, FolderPlus } from "lucide-vue-next";
|
||||
import { useQuery } from "@tanstack/vue-query";
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/vue-query";
|
||||
import axios from "axios";
|
||||
import { LicenseGroup } from "@/types";
|
||||
import { axiosInstance } from "@/client";
|
||||
import { LicenseGroup, CreateLicenseDto } from "@/types";
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const { data } = useQuery({
|
||||
queryKey: ["licenses"],
|
||||
|
@ -249,14 +255,27 @@ const { data } = useQuery({
|
|||
},
|
||||
});
|
||||
|
||||
const { isPending, mutate } = useMutation({
|
||||
mutationFn: async (newLicense: CreateLicenseDto) => {
|
||||
await axiosInstance.post("/licenses", newLicense);
|
||||
},
|
||||
onError: (error) => {
|
||||
snackbar.value = true;
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ["licenses"] });
|
||||
add.value = false;
|
||||
},
|
||||
});
|
||||
|
||||
function handlelogout() {
|
||||
store.setToken(null);
|
||||
}
|
||||
|
||||
async function submit(event: SubmitEventPromise) {
|
||||
const result = await event;
|
||||
if (result.valid) {
|
||||
console.log({
|
||||
if (result.valid && addLicenseGroup.value) {
|
||||
const data = {
|
||||
name: addLicenseName.value,
|
||||
group_id: addLicenseGroup.value,
|
||||
amount: addAmount.value,
|
||||
|
@ -264,12 +283,16 @@ async function submit(event: SubmitEventPromise) {
|
|||
start: addStartDate.value,
|
||||
stop: addStopDate.value,
|
||||
notes: addNotes.value,
|
||||
});
|
||||
};
|
||||
console.log(data);
|
||||
mutate(data);
|
||||
} else {
|
||||
console.log("Invalid");
|
||||
}
|
||||
}
|
||||
|
||||
const snackbar = ref(false);
|
||||
|
||||
//
|
||||
// GROUP SECTION
|
||||
//
|
||||
|
|
|
@ -20,21 +20,13 @@
|
|||
import HeaderBar from "./HeaderBar.vue";
|
||||
import CategoryContainer from "./CategoryContainer.vue";
|
||||
import { useQuery } from "@tanstack/vue-query";
|
||||
import axios from "axios";
|
||||
import { store } from "@/store";
|
||||
import { axiosInstance } from "@/client";
|
||||
import { LicenseGroup } from "@/types";
|
||||
|
||||
const { isPending, isError, data, error } = useQuery({
|
||||
queryKey: ["licenses"],
|
||||
queryFn: async () => {
|
||||
const res = await axios.get<LicenseGroup[]>(
|
||||
import.meta.env.VITE_BACKEND_URL + "/licenses",
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${store.token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
const res = await axiosInstance.get<LicenseGroup[]>("/licenses");
|
||||
return res.data;
|
||||
},
|
||||
});
|
||||
|
|
|
@ -12,3 +12,5 @@ export interface License {
|
|||
key: string;
|
||||
amount?: number;
|
||||
}
|
||||
|
||||
export type CreateLicenseDto = Omit<License, "id"> & { group_id: string };
|
||||
|
|
Loading…
Reference in a new issue