Skip to content

Commit 0176446

Browse files
luizhf42gustavosbarreto
authored andcommitted
refactor(ui): migrate Users store to Pinia
1 parent cb421de commit 0176446

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+354
-601
lines changed

ui/src/components/Account/AccountCreated.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939
<script setup lang="ts">
4040
import { computed, watch } from "vue";
4141
import { useRouter, useRoute } from "vue-router";
42-
import { useStore } from "@/store";
4342
import handleError from "@/utils/handleError";
4443
import useSnackbar from "@/helpers/snackbar";
4544
import useAuthStore from "@/store/modules/auth";
45+
import useUsersStore from "@/store/modules/users";
4646
4747
const props = defineProps<{
4848
messageKind: "sig" | "normal";
@@ -52,12 +52,12 @@ const props = defineProps<{
5252
5353
const emit = defineEmits(["show"]);
5454
const authStore = useAuthStore();
55-
const store = useStore();
55+
const usersStore = useUsersStore();
5656
const router = useRouter();
5757
const route = useRoute();
5858
const snackbar = useSnackbar();
5959
60-
const token = computed(() => store.getters["users/getSignToken"]);
60+
const token = computed(() => usersStore.signUpToken);
6161
6262
const showMessage = computed({
6363
get: () => props.show,
@@ -71,7 +71,7 @@ const buttonDataTest = computed(() => (isNormalMessage.value ? "resendEmail-btn"
7171
7272
const resendEmail = async () => {
7373
try {
74-
await store.dispatch("users/resendEmail", props.username);
74+
await usersStore.resendEmail(props.username);
7575
snackbar.showSuccess("Email successfully sent.");
7676
} catch (error) {
7777
snackbar.showError("Failed to send email.");
@@ -101,7 +101,7 @@ const handleAction = async () => {
101101
102102
watch(showMessage, (newValue) => {
103103
if (newValue && props.messageKind === "sig") {
104-
authStore.token = token.value;
104+
authStore.token = token.value as string;
105105
setTimeout(redirect, 5000);
106106
}
107107
});

ui/src/components/AuthMFA/MfaForceRecoveryMail.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ import * as yup from "yup";
5454
import { useField } from "vee-validate";
5555
import { computed, ref } from "vue";
5656
import axios, { AxiosError } from "axios";
57-
import { useStore } from "@/store";
5857
import handleError from "@/utils/handleError";
5958
import useSnackbar from "@/helpers/snackbar";
6059
import BaseDialog from "../BaseDialog.vue";
6160
import useAuthStore from "@/store/modules/auth";
61+
import useUsersStore from "@/store/modules/users";
62+
import { IUserPatch } from "@/interfaces/IUser";
6263
6364
const showDialog = ref(false);
64-
const store = useStore();
6565
const authStore = useAuthStore();
66+
const usersStore = useUsersStore();
6667
const snackbar = useSnackbar();
6768
const email = computed(() => authStore.email);
6869
const {
@@ -87,12 +88,11 @@ const {
8788
8889
const updateUserData = async () => {
8990
const data = {
90-
id: authStore.id,
9191
recovery_email: recoveryEmail.value,
92-
};
92+
} as IUserPatch;
9393
9494
try {
95-
await store.dispatch("users/patchData", data);
95+
await usersStore.patchData(data);
9696
authStore.updateUserData(data);
9797
snackbar.showSuccess("Recovery email updated successfully.");
9898
} catch (error) {

ui/src/components/AuthMFA/MfaSettings.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -261,15 +261,16 @@ import { useField } from "vee-validate";
261261
import { ref, computed, watch } from "vue";
262262
import QrcodeVue from "qrcode.vue";
263263
import axios, { AxiosError } from "axios";
264-
import { useStore } from "@/store";
265264
import handleError from "@/utils/handleError";
266265
import useSnackbar from "@/helpers/snackbar";
267266
import CopyWarning from "@/components/User/CopyWarning.vue";
268267
import BaseDialog from "../BaseDialog.vue";
269268
import useAuthStore from "@/store/modules/auth";
269+
import useUsersStore from "@/store/modules/users";
270+
import { IUserPatch } from "@/interfaces/IUser";
270271
271-
const store = useStore();
272272
const authStore = useAuthStore();
273+
const usersStore = useUsersStore();
273274
const snackbar = useSnackbar();
274275
const el = ref<number>(1);
275276
const emit = defineEmits(["update:recovery-email"]);
@@ -323,10 +324,9 @@ const goToNextStep = async () => {
323324
324325
const updateRecoveryEmail = async () => {
325326
try {
326-
await store.dispatch("users/patchData", {
327-
id: authStore.id,
327+
await usersStore.patchData({
328328
recovery_email: recoveryEmail.value,
329-
});
329+
} as IUserPatch);
330330
authStore.recoveryEmail = recoveryEmail.value;
331331
snackbar.showSuccess("Recovery email updated successfully.");
332332
emit("update:recovery-email", recoveryEmail.value);

ui/src/components/Billing/BillingWarning.vue

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,46 +43,16 @@
4343
import { computed } from "vue";
4444
import { actions, authorizer } from "@/authorizer";
4545
import hasPermission from "@/utils/permission";
46-
import { useStore } from "@/store";
4746
import BaseDialog from "../BaseDialog.vue";
4847
import useAuthStore from "@/store/modules/auth";
49-
import useBillingStore from "@/store/modules/billing";
50-
import useStatsStore from "@/store/modules/stats";
5148
52-
const store = useStore();
5349
const authStore = useAuthStore();
54-
const billingStore = useBillingStore();
55-
const { stats } = useStatsStore();
5650
51+
const showWarningDialog = defineModel({ default: false });
5752
const hasAuthorization = computed(() => {
5853
const { role } = authStore;
5954
return !!role && hasPermission(authorizer.role[role], actions.billing.subscribe);
6055
});
6156
62-
const close = () => {
63-
if (store.getters["users/statusUpdateAccountDialog"]) {
64-
store.dispatch("users/setStatusUpdateAccountDialog", false);
65-
} else if (
66-
store.getters["users/statusUpdateAccountDialogByDeviceAction"]
67-
) {
68-
store.dispatch(
69-
"users/setStatusUpdateAccountDialogByDeviceAction",
70-
false,
71-
);
72-
}
73-
};
74-
75-
const showWarningDialog = computed({
76-
get() {
77-
return (
78-
(store.getters["users/statusUpdateAccountDialog"]
79-
&& stats.registered_devices === 3
80-
&& !billingStore.isActive)
81-
|| store.getters["users/statusUpdateAccountDialogByDeviceAction"]
82-
);
83-
},
84-
set() {
85-
close();
86-
},
87-
});
57+
const close = () => { showWarningDialog.value = false; };
8858
</script>

ui/src/components/Connector/ConnectorForm.vue

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ import { useField } from "vee-validate";
108108
import * as yup from "yup";
109109
import { computed, ref, watch } from "vue";
110110
import { envVariables } from "@/envVariables";
111-
import { useStore } from "@/store";
112111
import { IConnectorPayload } from "@/interfaces/IConnector";
113112
import { parseCertificate, parsePrivateKeySsh } from "@/utils/validate";
114113
import hasPermission from "@/utils/permission";
@@ -117,6 +116,7 @@ import handleError from "@/utils/handleError";
117116
import useSnackbar from "@/helpers/snackbar";
118117
import BaseDialog from "../BaseDialog.vue";
119118
import useAuthStore from "@/store/modules/auth";
119+
import useUsersStore from "@/store/modules/users";
120120
121121
const props = defineProps<{
122122
isEditing: boolean;
@@ -128,12 +128,11 @@ const props = defineProps<{
128128
}>();
129129
130130
const authStore = useAuthStore();
131+
const usersStore = useUsersStore();
131132
const showDialog = defineModel<boolean>({ default: false });
132133
const emit = defineEmits(["update"]);
133134
const snackbar = useSnackbar();
134135
135-
const store = useStore();
136-
137136
// eslint-disable-next-line vue/max-len
138137
const ipAddressRegex = /^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})\.(25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})$/;
139138
@@ -301,7 +300,7 @@ const saveConnector = async () => {
301300
}
302301
303302
if (envVariables.isCommunity) {
304-
store.commit("users/setShowPaywall", true);
303+
usersStore.showPaywall = true;
305304
return;
306305
}
307306
try {

ui/src/components/Devices/DeviceAcceptWarning.vue

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,19 @@
3030
import { computed } from "vue";
3131
import { actions, authorizer } from "@/authorizer";
3232
import hasPermission from "@/utils/permission";
33-
import { useStore } from "@/store";
3433
import BaseDialog from "../BaseDialog.vue";
3534
import useAuthStore from "@/store/modules/auth";
3635
import useDevicesStore from "@/store/modules/devices";
3736
3837
const authStore = useAuthStore();
3938
const devicesStore = useDevicesStore();
40-
const store = useStore();
4139
const duplicatedDeviceName = computed(() => devicesStore.duplicatedDeviceName);
42-
const showDialog = computed(() => store.getters["users/deviceDuplicationError"]);
40+
const showDialog = computed(() => !!duplicatedDeviceName.value);
4341
4442
const hasAuthorization = computed(() => {
4543
const { role } = authStore;
4644
return !!role && hasPermission(authorizer.role[role], actions.billing.subscribe);
4745
});
4846
49-
const close = () => { store.dispatch("users/setDeviceDuplicationOnAcceptance", false); };
47+
const close = () => { devicesStore.duplicatedDeviceName = ""; };
5048
</script>

ui/src/components/Devices/DeviceActionButton.vue

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
<script setup lang="ts">
5353
import { ref, computed } from "vue";
5454
import { AxiosError } from "axios";
55-
import { useStore } from "@/store";
5655
import { authorizer, actions } from "@/authorizer";
5756
import hasPermission from "@/utils/permission";
5857
import { capitalizeText } from "@/utils/string";
@@ -79,7 +78,6 @@ const props = withDefaults(defineProps<DeviceActionButtonProps>(), {
7978
});
8079
8180
const emit = defineEmits(["update"]);
82-
const store = useStore();
8381
const authStore = useAuthStore();
8482
const billingStore = useBillingStore();
8583
const devicesStore = useDevicesStore();
@@ -139,15 +137,14 @@ const acceptDevice = async () => {
139137
const axiosError = error as AxiosError;
140138
switch (axiosError.response?.status) {
141139
case 402:
142-
store.dispatch("users/setStatusUpdateAccountDialogByDeviceAction", true);
140+
billingStore.showBillingWarning = true;
143141
snackbar.showError("Couldn't accept the device. Check your billing status and try again.");
144142
break;
145143
case 403:
146144
snackbar.showError("You reached the maximum amount of accepted devices in this namespace.");
147145
break;
148146
case 409:
149147
devicesStore.duplicatedDeviceName = props.name;
150-
store.dispatch("users/setDeviceDuplicationOnAcceptance", true);
151148
snackbar.showError("A device with that name already exists in the namespace. Rename it and try again.");
152149
break;
153150
default:

ui/src/components/Sessions/SessionPlay.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import useSnackbar from "@/helpers/snackbar";
5454
import BaseDialog from "../BaseDialog.vue";
5555
import useAuthStore from "@/store/modules/auth";
5656
import useSessionsStore from "@/store/modules/sessions";
57-
import { useStore } from "@/store";
57+
import useUsersStore from "@/store/modules/users";
5858
5959
const props = defineProps<{
6060
uid: string;
@@ -63,9 +63,9 @@ const props = defineProps<{
6363
}>();
6464
6565
const showDialog = ref(false);
66-
const store = useStore();
6766
const authStore = useAuthStore();
6867
const sessionsStore = useSessionsStore();
68+
const usersStore = useUsersStore();
6969
const snackbar = useSnackbar();
7070
const disabled = computed(() => !props.recorded || !props.authenticated);
7171
const loading = ref(false);
@@ -103,7 +103,7 @@ const displayDialog = async () => {
103103
104104
const openDialog = () => {
105105
if (envVariables.isCommunity) {
106-
store.commit("users/setShowPaywall", true);
106+
usersStore.showPaywall = true;
107107
return;
108108
}
109109
displayDialog();

ui/src/components/Setting/SettingProfile.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ import { useDisplay } from "vuetify";
230230
import { useField } from "vee-validate";
231231
import axios, { AxiosError } from "axios";
232232
import * as yup from "yup";
233-
import { useStore } from "@/store";
234233
import handleError from "@/utils/handleError";
235234
import MfaSettings from "../AuthMFA/MfaSettings.vue";
236235
import MfaDisable from "../AuthMFA/MfaDisable.vue";
@@ -240,11 +239,12 @@ import { envVariables } from "@/envVariables";
240239
import ChangePassword from "../User/ChangePassword.vue";
241240
import useSnackbar from "@/helpers/snackbar";
242241
import useAuthStore from "@/store/modules/auth";
242+
import useUsersStore from "@/store/modules/users";
243243
244244
type ErrorResponseData = { field: string; message: string }[];
245245
246-
const store = useStore();
247246
const authStore = useAuthStore();
247+
const usersStore = useUsersStore();
248248
const snackbar = useSnackbar();
249249
const editDataStatus = ref(false);
250250
const editPasswordStatus = ref(false);
@@ -380,7 +380,7 @@ const updateUserData = async () => {
380380
};
381381
382382
try {
383-
await store.dispatch("users/patchData", data);
383+
usersStore.patchData(data);
384384
authStore.updateUserData(data);
385385
snackbar.showSuccess("Profile data updated successfully.");
386386
enableEdit("data");

ui/src/components/User/ChangePassword.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,14 @@ import * as yup from "yup";
7474
import { useField } from "vee-validate";
7575
import { computed, ref } from "vue";
7676
import axios, { AxiosError } from "axios";
77-
import { useStore } from "@/store";
7877
import handleError from "@/utils/handleError";
7978
import useSnackbar from "@/helpers/snackbar";
8079
import BaseDialog from "../BaseDialog.vue";
8180
import useAuthStore from "@/store/modules/auth";
81+
import useUsersStore from "@/store/modules/users";
8282
83-
const store = useStore();
8483
const authStore = useAuthStore();
84+
const usersStore = useUsersStore();
8585
const snackbar = useSnackbar();
8686
const showDialog = defineModel({ default: false });
8787
@@ -163,7 +163,7 @@ const updatePassword = async () => {
163163
};
164164
165165
try {
166-
await store.dispatch("users/patchPassword", data);
166+
await usersStore.patchPassword(data);
167167
snackbar.showSuccess("Password updated successfully.");
168168
close();
169169
} catch (error: unknown) {

0 commit comments

Comments
 (0)