From bfb53938fd4911723f17c9b44a83e00ef788399b Mon Sep 17 00:00:00 2001
From: tetuaoro <65575727+tetuaoro@users.noreply.github.com>
Date: Wed, 18 Sep 2024 12:25:01 +0200
Subject: [PATCH] update: step page
- first step to choose a language
- use red color in light mode
- validate step before move toward
---
src/app/components/step/Progress.vue | 6 +-
src/app/pages/setup.vue | 123 +++++++++++++++++++++------
src/locales/en.json | 3 +-
src/locales/fr.json | 3 +-
4 files changed, 106 insertions(+), 29 deletions(-)
diff --git a/src/app/components/step/Progress.vue b/src/app/components/step/Progress.vue
index 5547d918..f974df99 100644
--- a/src/app/components/step/Progress.vue
+++ b/src/app/components/step/Progress.vue
@@ -3,8 +3,8 @@
v-for="n in totalSteps"
:key="n"
:class="[
- 'step grow h-[3px] mx-4',
- step >= n ? 'dark:bg-white' : 'dark:bg-gray-500',
+ 'step grow h-[3px] mx-3',
+ step >= n ? 'bg-red-800 dark:bg-white' : 'bg-gray-500',
]"
>
@@ -17,7 +17,7 @@ defineProps({
},
totalSteps: {
type: Number,
- default: 4,
+ default: 5,
},
});
diff --git a/src/app/pages/setup.vue b/src/app/pages/setup.vue
index 3d128274..1a98a09c 100644
--- a/src/app/pages/setup.vue
+++ b/src/app/pages/setup.vue
@@ -8,7 +8,22 @@
-
{{ $t('setup.msg') }}
+
{{ $t('setup.msgStepOne') }}
+
+
+
+
+
-
+
-
+
-
+
@@ -89,28 +112,36 @@ import { FetchError } from 'ofetch';
const { t } = useI18n();
+type SetupError = {
+ title: string;
+ message: string;
+};
+
const username = ref
(null);
const password = ref(null);
const accept = ref(true);
const authStore = useAuthStore();
const step = ref(1);
-
-function increaseStep() {
- if (step.value < 4) step.value += 1;
-}
-
-function decreaseStep() {
- if (step.value > 1) step.value -= 1;
-}
-
-type SetupError = {
- title: string;
- message: string;
-};
-
+const stepInvalide = ref([]);
const setupError = ref(null);
+const langs = [
+ {
+ value: 'de',
+ name: 'Deutsch',
+ },
+ {
+ value: 'en',
+ name: 'English',
+ },
+ {
+ value: 'de',
+ name: 'Français',
+ },
+];
+
+// TODO: improve error handling
watch(setupError, (value) => {
if (value) {
setTimeout(() => {
@@ -119,7 +150,49 @@ watch(setupError, (value) => {
}
});
-async function _newAccount() {
+async function increaseStep() {
+ try {
+ if (step.value === 1) {
+ /* lang */
+ }
+
+ if (step.value === 2) {
+ await newAccount();
+ stepInvalide.value.push(1);
+ }
+
+ if (step.value === 3) {
+ /* host/port */
+ }
+
+ if (step.value === 4) {
+ /* migration */
+ }
+
+ if (step.value === 5) {
+ /* validation/welcome */
+ }
+
+ if (step.value < 5) step.value += 1;
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
+ } catch (error) {
+ /* throw in functions */
+ }
+}
+
+// TODO: improve while user reload the page, might use server check
+/* Check if previous steps are invalide (mean successful executed). */
+function towardStepValide() {
+ return stepInvalide.value.includes(step.value - 1);
+}
+
+function decreaseStep() {
+ if (towardStepValide()) return;
+
+ if (step.value > 1) step.value -= 1;
+}
+
+async function newAccount() {
if (!username.value || !password.value) return;
try {
@@ -138,6 +211,8 @@ async function _newAccount() {
message: error.data.message,
};
}
+ // increaseStep fn
+ throw error;
}
}
diff --git a/src/locales/en.json b/src/locales/en.json
index a77f3be6..5700f073 100644
--- a/src/locales/en.json
+++ b/src/locales/en.json
@@ -14,7 +14,8 @@
"confirmPassword": "Confirm Password",
"setup": {
"welcome": "Welcome to your first setup of wg-easy !",
- "msg": "Please first enter an admin username and a strong secure password. This information will be used to log in to your administration panel.",
+ "msgStepOne": "Please choose a default language.",
+ "msgStepTwo": "Please first enter an admin username and a strong secure password. This information will be used to log in to your administration panel.",
"newPassword": "New Password",
"accept": "I accept the condition",
"submitBtn": "Create admin account",
diff --git a/src/locales/fr.json b/src/locales/fr.json
index 5f74251d..8f52b200 100644
--- a/src/locales/fr.json
+++ b/src/locales/fr.json
@@ -14,7 +14,8 @@
"confirmPassword": "Confirmer le mot de passe",
"setup": {
"welcome": "Bienvenue dans votre première configuration de wg-easy !",
- "msg": "Veuillez renseigner votre nom d'utilisateur et votre mot de passe. Ces informations seront utilisées pour vous connecter à votre page d'administration.",
+ "msgStepOne": "Sélectionner votre langue.",
+ "msgStepTwo": "Veuillez renseigner votre nom d'utilisateur et votre mot de passe. Ces informations seront utilisées pour vous connecter à votre page d'administration.",
"newPassword": "Nouveau mot de passe",
"accept": "J'accepte les conditions d'utilisation",
"submitBtn": "Créer un compte administrateur",