Merge pull request #182 from dderbentsov/UC-162

[WIP] Фикс апдейта данных клиента и просроченного токена
This commit is contained in:
frontgavrilin
2022-12-07 17:38:10 +03:00
committed by GitHub
9 changed files with 62 additions and 60 deletions

View File

@@ -449,7 +449,7 @@ export default {
background-color: var(--default-white) background-color: var(--default-white)
border-radius: 4px border-radius: 4px
width: 634px width: 634px
min-height: 700px min-height: 585px
box-shadow: var(--default-shadow) box-shadow: var(--default-shadow)
.title .title

View File

@@ -104,16 +104,10 @@ export default {
saveEmployeesData(res) { saveEmployeesData(res) {
this.employeesData = res.results; this.employeesData = res.results;
}, },
logout() {
localStorage.removeItem("tokenAccess");
this.$router.push("/login");
},
fetchEmployeesData() { fetchEmployeesData() {
fetchWrapper.get("general/employee/").then((res) => { fetchWrapper
if (res.type === "client_error") { .get("general/employee/")
this.logout(); .then((res) => this.saveEmployeesData(res));
} else this.saveEmployeesData(res);
});
}, },
fetchEventsData() { fetchEventsData() {
fetchWrapper fetchWrapper

View File

@@ -118,10 +118,6 @@ export default {
this.fetchDataClients(); this.fetchDataClients();
} }
}, },
logout() {
localStorage.removeItem("tokenAccess");
this.$router.push("/login");
},
async fetchDataClients() { async fetchDataClients() {
let response = {}; let response = {};
if (this.textSearch) { if (this.textSearch) {
@@ -130,32 +126,24 @@ export default {
this.limit this.limit
}&offset=${(this.currentTablePage - 1) * this.limit}` }&offset=${(this.currentTablePage - 1) * this.limit}`
); );
if (response.type === "client_error") { this.saveDataClients(response);
this.logout(); this.saveFilteredClientsCount(response);
} else { this.paginationInfo = {
this.saveDataClients(response); currentPage: this.currentTablePage,
this.saveFilteredClientsCount(response); length: this.calculatePageCount(this.filteredClientsCount),
this.paginationInfo = { };
currentPage: this.currentTablePage,
length: this.calculatePageCount(this.filteredClientsCount),
};
}
} else { } else {
response = await fetchWrapper.get( response = await fetchWrapper.get(
`general/person/?limit=${this.limit}&offset=${ `general/person/?limit=${this.limit}&offset=${
(this.currentTablePage - 1) * this.limit (this.currentTablePage - 1) * this.limit
}` }`
); );
if (response.type === "client_error") { this.saveDataClients(response);
this.logout(); this.saveClientsCount(response);
} else { this.paginationInfo = {
this.saveDataClients(response); currentPage: this.currentTablePage,
this.saveClientsCount(response); length: this.calculatePageCount(this.clientsCount),
this.paginationInfo = { };
currentPage: this.currentTablePage,
length: this.calculatePageCount(this.clientsCount),
};
}
} }
}, },
calculatePageCount(count) { calculatePageCount(count) {

View File

@@ -212,29 +212,31 @@ export default {
(el) => el.text === this.dataClient.priority (el) => el.text === this.dataClient.priority
); );
let data = {}; let data = {};
if ( let clientName = `${this.client.last_name || ""} ${
this.dataClient.age !== this.client.birth_date && this.client.first_name || ""
this.dataClient.age } ${this.client.patronymic || ""}`;
) {
if (!this.dataClient.fullName) this.dataClient.fullName = clientName;
else if (this.dataClient.fullName !== clientName)
data.full_name = this.dataClient.fullName;
if (this.dataClient.age !== this.client.birth_date && this.dataClient.age)
data.birth_date = this.dataClient.age; data.birth_date = this.dataClient.age;
else if (!this.dataClient.age) {
this.addErrorNotification(
"Пожалуйста, введите дату рождения корректно"
);
this.dataClient.age = this.client.birth_date || "";
} }
if ( if (foundElement.id !== this.client.priority)
foundElement.id !== this.client.priority && data.priority = foundElement.id;
foundElement.text !== "-"
) {
data.priority = foundElement.priority;
} else if (foundElement.text === "-") {
data.priority = 4;
}
if ( if (
data.birth_date && data.birth_date &&
moment(data.birth_date).isAfter(moment().format("YYYY-MM-DD")) moment(data.birth_date).isAfter(moment().format("YYYY-MM-DD"))
) { ) {
this.addErrorNotification(); this.addErrorNotification("Дата рождения позже текущего дня");
this.dataClient.age = this.client.birth_date; this.dataClient.age = this.client.birth_date || "";
} else } else if (!Object.keys(data).length == 0)
fetchWrapper.post(`general/person/${this.client.id}/update/`, { fetchWrapper.post(`general/person/${this.client.id}/update/`, {
full_name: this.dataClient.fullName,
...data, ...data,
}); });
}, },
@@ -264,16 +266,24 @@ export default {
this.client.contacts.forEach((el) => { this.client.contacts.forEach((el) => {
if ( if (
el.kind === "PHONE" && el.kind === "PHONE" &&
this.dataClient.phone.username.length === 18 &&
el.username !== this.dataClient.phone.username el.username !== this.dataClient.phone.username
) { ) {
updateContacts.push(this.dataClient.phone); updateContacts.push(this.dataClient.phone);
} } else
this.dataClient.phone.username =
this.client.contacts.find((el) => el.kind === "PHONE")?.username ||
"";
if ( if (
el.kind === "EMAIL" && el.kind === "EMAIL" &&
this.dataClient.email.username &&
el.username !== this.dataClient.email.username el.username !== this.dataClient.email.username
) { ) {
updateContacts.push(this.dataClient.email); updateContacts.push(this.dataClient.email);
} } else
this.dataClient.email.username =
this.client.contacts.find((el) => el.kind === "EMAIL")?.username ||
"";
}); });
createContacts.forEach((el) => this.postCreateContact(el)); createContacts.forEach((el) => this.postCreateContact(el));
// deleteContacts.forEach((el) => this.postDeleteContact(el)); // deleteContacts.forEach((el) => this.postDeleteContact(el));
@@ -336,11 +346,11 @@ export default {
5000 5000
); );
}, },
addErrorNotification() { addErrorNotification(message) {
addNotification( addNotification(
"Некорректная дата рождения", "Некорректная дата рождения",
"Некорректная дата рождения", "Некорректная дата рождения",
"Дата рождения позже текущего дня", message,
"error", "error",
5000 5000
); );

View File

@@ -87,7 +87,7 @@ export default {
<style lang="sass" scoped> <style lang="sass" scoped>
.wrapper-info .wrapper-info
min-height: 443px min-height: 336px
max-height: 443px max-height: 443px
overflow-y: auto overflow-y: auto
color: var(--font-grey-color) color: var(--font-grey-color)

View File

@@ -39,18 +39,22 @@
.flex.flex-col(class="gap-y-1.5") .flex.flex-col(class="gap-y-1.5")
span.text-sm Номер СНИЛС span.text-sm Номер СНИЛС
base-input.input-info( base-input.input-info(
disabled,
v-mask="'###-###-### ##'", v-mask="'###-###-### ##'",
v-model:value="identityDocument.snils.numba", v-model:value="identityDocument.snils.numba",
placeholder="000000000 00", placeholder="000000000 00",
:width-input="277" :width-input="277",
:style="{backgroundColor: 'var(--bg-disable-grey-color)'}"
) )
.flex.flex-col(class="gap-y-1.5") .flex.flex-col(class="gap-y-1.5")
span.text-sm Номер ИНН span.text-sm Номер ИНН
base-input.input-info( base-input.input-info(
disabled,
v-mask="'############'", v-mask="'############'",
v-model:value="identityDocument.inn.numba", v-model:value="identityDocument.inn.numba",
placeholder="000000000000", placeholder="000000000000",
:width-input="277" :width-input="277",
:style="{backgroundColor: 'var(--bg-disable-grey-color)'}"
) )
.px-4 .px-4
base-button(@click="saveClient" :size="40") base-button(@click="saveClient" :size="40")

View File

@@ -9,7 +9,8 @@
@click.stop, @click.stop,
type="text", type="text",
v-model:value="value.fullName", v-model:value="value.fullName",
:width-input="300" :width-input="300",
placeholder="Фамилия Имя Отчество"
) )
</template> </template>

View File

@@ -8,7 +8,7 @@
.absolute.icon-cancel-mini.delete.flex.w-4.h-4.justify-center.items-center.bottom-4.left-2( .absolute.icon-cancel-mini.delete.flex.w-4.h-4.justify-center.items-center.bottom-4.left-2(
v-if="isOpenChange", v-if="isOpenChange",
:id="network.kind", :id="network.kind",
@click="(e) => deleteNetwork(e)" @click.stop="(e) => deleteNetwork(e)"
) )
.flex.relative.pb-2(class="pl-[46px]") .flex.relative.pb-2(class="pl-[46px]")
base-button( base-button(

View File

@@ -1,3 +1,5 @@
import router from "@/router";
function prepareUrl(url) { function prepareUrl(url) {
if (url.startsWith("http")) return url; if (url.startsWith("http")) return url;
return `http://45.84.227.122:8080/api/${url}`; return `http://45.84.227.122:8080/api/${url}`;
@@ -12,7 +14,10 @@ function handleRequest(method, url, headers, attempts, body, type) {
})(); })();
}) })
.then((res) => { .then((res) => {
if (res) return res.json(); if (res.status === 401) {
localStorage.removeItem("tokenAccess");
return router.push("/login");
} else if (res) return res.json();
}) })
.catch((err) => { .catch((err) => {
return err; return err;