Skip to content

Commit

Permalink
fix: 🐛 Fix reset password redirection (MTES-MCT#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattboll authored Mar 14, 2024
1 parent 3d77294 commit 2f0ca04
Showing 1 changed file with 135 additions and 140 deletions.
275 changes: 135 additions & 140 deletions tenantv3/src/components/NameInformationForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
<p>
{{ $t("nameinformationform.unlink-fc-content") }}
<span v-if="user?.passwordEnabled">
{{
$t("nameinformationform.unlink-fc-content-password-exists")
}}</span
{{ $t("nameinformationform.unlink-fc-content-password-exists") }}</span
>
<span v-else>{{
$t("nameinformationform.unlink-fc-content-password-undefined")
Expand All @@ -30,69 +28,66 @@
</ConfirmModal>
</div>

<Form
class="fr-mt-3w"
name="nameInformationForm"
@submit="handleNameInformation">
<div class="fr-grid-row fr-grid-row--center">
<div class="fr-col-12 fr-mb-3w">
<TextField
name="lastname"
:fieldLabel="$t('nameinformationform.lastname')"
validation-rules="onlyAlpha"
v-model.trim="lastname"
:required="true"
:disabled="user?.franceConnect"
/>
<button
class="fr-btn fr-btn--sm fr-btn--tertiary fr-btn--icon-left fr-icon-add-line fr-mt-1w"
v-if="!displayPreferredNameField"
@click="displayPreferredNameField = true"
type="button"
title="{{ $t('nameinformationform.add-preferredname') }}"
>
{{ $t("nameinformationform.add-preferredname") }}
</button>
</div>
<div class="fr-col-12 fr-mb-3w" v-if="displayPreferredNameField">
<TextField
name="preferredname"
:fieldLabel="$t('nameinformationform.preferredname')"
validation-rules="onlyAlpha"
v-model.trim="preferredname"
>
<template v-slot:right>
<button
class="fr-btn fr-btn--tertiary fr-icon-close-line"
:title="$t('nameinformationform.delete-preferredname')"
@click="deletePreferredName()"
>
{{ $t("nameinformationform.delete-preferredname") }}
</button>
</template>
</TextField>
</div>
<div class="fr-col-12 fr-mb-3w">
<TextField
name="firstname"
:fieldLabel="$t('nameinformationform.firstname')"
validation-rules="onlyAlpha"
v-model.trim="firstname"
:required="true"
:disabled="user?.franceConnect"
/>
</div>
<div class="fr-col-12 fr-mb-3w">
<TextField
name="zipcode"
:fieldLabel="$t('nameinformationform.zipcode')"
validation-rules="zipcode"
v-model="zipcode"
/>
</div>
<Form class="fr-mt-3w" name="nameInformationForm" @submit="handleNameInformation">
<div class="fr-grid-row fr-grid-row--center">
<div class="fr-col-12 fr-mb-3w">
<TextField
name="lastname"
:fieldLabel="$t('nameinformationform.lastname')"
validation-rules="onlyAlpha"
v-model.trim="lastname"
:required="true"
:disabled="user?.franceConnect"
/>
<button
class="fr-btn fr-btn--sm fr-btn--tertiary fr-btn--icon-left fr-icon-add-line fr-mt-1w"
v-if="!displayPreferredNameField"
@click="displayPreferredNameField = true"
type="button"
title="{{ $t('nameinformationform.add-preferredname') }}"
>
{{ $t("nameinformationform.add-preferredname") }}
</button>
</div>
<div class="fr-col-12 fr-mb-3w" v-if="displayPreferredNameField">
<TextField
name="preferredname"
:fieldLabel="$t('nameinformationform.preferredname')"
validation-rules="onlyAlpha"
v-model.trim="preferredname"
>
<template v-slot:right>
<button
class="fr-btn fr-btn--tertiary fr-icon-close-line"
:title="$t('nameinformationform.delete-preferredname')"
@click="deletePreferredName()"
>
{{ $t("nameinformationform.delete-preferredname") }}
</button>
</template>
</TextField>
</div>
<div class="fr-col-12 fr-mb-3w">
<TextField
name="firstname"
:fieldLabel="$t('nameinformationform.firstname')"
validation-rules="onlyAlpha"
v-model.trim="firstname"
:required="true"
:disabled="user?.franceConnect"
/>
</div>
<ProfileFooter :showBack="false"></ProfileFooter>
</Form>
<div class="fr-col-12 fr-mb-3w">
<TextField
name="zipcode"
:fieldLabel="$t('nameinformationform.zipcode')"
validation-rules="zipcode"
v-model="zipcode"
/>
</div>
</div>
<ProfileFooter :showBack="false"></ProfileFooter>
</Form>
</NakedCard>
</div>
</template>
Expand All @@ -110,92 +105,92 @@ import TextField from "df-shared-next/src/components/form/TextField.vue";
import useTenantStore from "@/stores/tenant-store";
import { computed, onBeforeMount, ref } from "vue";
import { useRouter } from "vue-router";
import { useLoading } from 'vue-loading-overlay';
import { useLoading } from "vue-loading-overlay";
const store = useTenantStore();
const user = computed(() => store.userToEdit);
const store = useTenantStore();
const user = computed(() => store.userToEdit);
const router = useRouter();
const openUnlinkModal = ref(false);
const displayPreferredNameField = ref(false);
const openUnlinkModal = ref(false);
const displayPreferredNameField = ref(false);
const firstname = ref("");
const lastname = ref("");
const preferredname = ref("");
const zipcode = ref("");
const $loading = useLoading({});
const firstname = ref("");
const lastname = ref("");
const preferredname = ref("");
const zipcode = ref("");
const $loading = useLoading({});
onBeforeMount(() => {
firstname.value = user.value?.firstName || "";
lastname.value = user.value?.lastName || "";
preferredname.value = UtilsService.capitalize(user.value?.preferredName || "");
zipcode.value = user.value?.zipCode || "";
displayPreferredNameField.value = preferredname.value !== "";
})
onBeforeMount(() => {
firstname.value = user.value?.firstName || "";
lastname.value = user.value?.lastName || "";
preferredname.value = UtilsService.capitalize(user.value?.preferredName || "");
zipcode.value = user.value?.zipCode || "";
displayPreferredNameField.value = preferredname.value !== "";
});
function deletePreferredName() {
preferredname.value = "";
displayPreferredNameField.value = false;
}
function deletePreferredName() {
preferredname.value = "";
displayPreferredNameField.value = false;
}
function unlinkFranceConnect() {
openUnlinkModal.value = false;
const loader = $loading.show();
if (!user.value) {
return;
}
store
.unlinkFranceConnect(user.value)
.then(
() => {
// if user has not password redirect to resetpassword
if (!user.value?.passwordEnabled) {
router.push("/reset-password/null");
}
},
(error) => {
console.dir(error);
}
)
.finally(() => {
loader.hide();
});
function unlinkFranceConnect() {
openUnlinkModal.value = false;
const loader = $loading.show();
if (!user.value) {
return;
}
function handleNameInformation() {
if (!user.value) {
return;
}
if (
user.value.firstName === firstname.value &&
user.value.lastName === lastname.value &&
user.value.preferredName === preferredname.value &&
user.value.zipCode === zipcode.value
) {
router.push({ name: "TenantType" });
return;
}
const loader = $loading.show();
store.updateUserFirstname(firstname.value);
store.updateUserLastname(lastname.value);
store.updateUserPreferredname(preferredname.value);
store.updateUserZipcode(zipcode.value);
store
.setNames(user.value)
.then(
() => {
AnalyticsService.confirmName();
router.push({ name: "TenantType" });
},
(error) => {
console.dir(error);
store
.unlinkFranceConnect(user.value)
.then(
() => {
// if user has not password redirect to resetpassword
if (!user.value?.passwordEnabled) {
window.location.href = import.meta.env.VITE_RESET_PASSWORD_URL;
}
)
.finally(() => {
loader.hide();
});
},
(error) => {
console.dir(error);
}
)
.finally(() => {
loader.hide();
});
}
function handleNameInformation() {
if (!user.value) {
return;
}
if (
user.value.firstName === firstname.value &&
user.value.lastName === lastname.value &&
user.value.preferredName === preferredname.value &&
user.value.zipCode === zipcode.value
) {
router.push({ name: "TenantType" });
return;
}
const loader = $loading.show();
store.updateUserFirstname(firstname.value);
store.updateUserLastname(lastname.value);
store.updateUserPreferredname(preferredname.value);
store.updateUserZipcode(zipcode.value);
store
.setNames(user.value)
.then(
() => {
AnalyticsService.confirmName();
router.push({ name: "TenantType" });
},
(error) => {
console.dir(error);
}
)
.finally(() => {
loader.hide();
});
}
</script>

<style scoped lang="scss">
Expand Down

0 comments on commit 2f0ca04

Please sign in to comment.