Add Group
@@ -24,7 +24,7 @@
{
- const res = await axios.get(
- import.meta.env.VITE_BACKEND_URL + "/licenses",
- {
- headers: {
- Authorization: `Bearer ${store.token}`,
- },
- }
- );
+ const res = await axiosInstance.get("/licenses");
return res.data;
},
select: (data) => {
@@ -220,7 +212,7 @@ const { data } = useQuery({
},
});
-const { isPending, mutate } = useMutation({
+const { mutate: licenseMutate } = useMutation({
mutationFn: async (newLicense: CreateLicenseDto) => {
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() {
store.setToken(null);
}
@@ -245,12 +250,25 @@ async function submit(event: SubmitEventPromise) {
group_id: addLicenseGroup.value,
amount: addAmount.value,
key: addLicenseKey.value,
- start: addStartDate.value,
- stop: addStopDate.value,
+ start: addStartDate.value ?? null,
+ end: addStopDate.value ?? null,
notes: addNotes.value,
};
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 {
console.log("Invalid");
}
@@ -263,7 +281,7 @@ const snackbar = ref(false);
//
const group = ref(false); // Dialog for Group
-const groupLicenseName = ref("");
+const groupGroupName = ref("");
// Rules for Group Dialog
const licenseGroupRules = [
@@ -312,12 +330,6 @@ const addNotes = ref("");
// Date Picker
const addStartDate = ref();
const addStopDate = ref();
-
-//
-// EDIT SECTION
-//
-
-const edit = ref(false);