Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: исправление кнопки отправки формы на странице контакты #485

Merged
merged 4 commits into from
Sep 11, 2023

Conversation

AleksandrDronov
Copy link
Collaborator

Описание

Исправление кнопки отправки формы на странице контакты

Ссылка на задачу

На странице контакты. При нажатии кнопки "Отправить" ничего не происходит

@@ -17,6 +18,10 @@ import { validEmailRegexp } from 'shared/constants/regexps';

import type { NextPage } from 'next';

interface ErrorResponse {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

в fetcher уже есть такой тип, можно экспортировать

@@ -1,3 +1,4 @@
/* eslint-disable camelcase */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

переименуй ветку как bugfix/....., писал об этом в чатике

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут я руководствовался тем, что написано в проекте.
image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, тут окей, думал нет соглашения в проекте, давай тогда ему придерживаться

@@ -162,10 +167,12 @@ const Contacts: NextPage = () => {
},
body: JSON.stringify(data),
});
} catch ([status, errors]) {
} catch (err) {
// TODO: добавить проверку типов выброшенного исключения, пока считаем, что всегда получаем ответ API
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

И давай раз уж тут есть TODO, сделаем ее

  1. Добавь тут обработку исключения
  2. И чтобы не использовать as давай будем проверять, что ошибка соответствует определенному типу (сделай это функцией чтобы мы использовали ее и в других компонентах), а такая уже есть... isHttpRequestError

@@ -27,7 +27,10 @@ const fetchResource = (httpClient: typeof fetch) => async <T>(path: string, opti
export const fetcher = fetchResource(fetch);

async function handleResponse<T>(response: Response) {
const payload = await response.json();
let payload;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

я так понимаю, что ты это добавил потому что бэк ответа не присылает?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ага. Бек присылет пустой body, поэтому без этой проверки возникает ошибка.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Так, ну тут бы я не стал завязываться на статус, сейчас в твоей условии если где-то придет статус 201 с телом, то он проигнорируется, плюс разработчикам не очевидно что это такое

Ломается у тебя тут на парсинге поэтому есть несколько вариантов это поправить, тебе тут надо добавить проверку или обработка исключений, попробуй подумать сам, если что приходи

}

return payload as T;
return response.json()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, тут все окей, только думаю лучше будет выглядеть с try catch и async/await чтобы все красиво было и придерживалось кодстайла

},
});
}
if (statusCode === 400) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

а почему тут добавилась проверка на 400 статус?

Copy link
Collaborator Author

@AleksandrDronov AleksandrDronov Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут я разделил ошибки по статусу. В случае 400 с сервера приходят тексты ошибок и мы меняем сотояние формы, а если какая-либо другая будет, то нет.

@AlMkin AlMkin merged commit e2ed6f0 into develop Sep 11, 2023
1 check passed
@AlMkin AlMkin deleted the bugfix-contacts-form branch September 11, 2023 15:33
AlMkin pushed a commit that referenced this pull request Sep 14, 2023
* fix: исправление поля текст сообщения на странице контакты

* fix: исправление кнопки отправки формы на странице контакты (#485)

* fix: исправление кнопки отправки формы на странице контакты

* fix: исправление кнопки отправки формы на странице контакты (доработка по замечаниям ревью)

* fix: исправление кнопки отправки формы на странице контакты (ревью)

* fix: исправление кнопки отправки формы на странице контакты (корректировка функции handleResponse)

* fix: удалены пропсы ограничивающие высоту и ширину в textarea

* fix: исправление поля текст сообщения на странице контакты

* fix: удалены пропсы ограничивающие высоту и ширину в textarea

* fix: правки после ревью

---------

Co-authored-by: Aleksandr Dronov <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants