diff --git a/app/javascript/controllers/autosave_controller.ts b/app/javascript/controllers/autosave_controller.ts index 863794195..0a3cc0570 100644 --- a/app/javascript/controllers/autosave_controller.ts +++ b/app/javascript/controllers/autosave_controller.ts @@ -1,13 +1,13 @@ -import { httpRequest, ResponseError, getConfig } from '@utils'; -import { matchInputElement, isButtonElement } from '@coldwired/utils'; +import { isButtonElement, matchInputElement } from '@coldwired/utils'; +import { getConfig, httpRequest, ResponseError } from '@utils'; -import { ApplicationController } from './application_controller'; import { AutoUpload } from '../shared/activestorage/auto-upload'; import { - FileUploadError, + ERROR_CODE_READ, FAILURE_CLIENT, - ERROR_CODE_READ + FileUploadError } from '../shared/activestorage/file-upload-error'; +import { ApplicationController } from './application_controller'; const { autosave: { debounce_delay } @@ -182,7 +182,7 @@ export class AutosaveController extends ApplicationController { .catch((e) => { const error = e as FileUploadError; - this.globalDispatch('autosave:error'); + this.globalDispatch('autosave:error', { error }); // Report unexpected client errors to Sentry. // (But ignore usual client errors, or errors we can monitor better on the server side.) diff --git a/app/javascript/controllers/date_input_hint_controller.ts b/app/javascript/controllers/date_input_hint_controller.ts index 8eacd6d53..d7cad2ebf 100644 --- a/app/javascript/controllers/date_input_hint_controller.ts +++ b/app/javascript/controllers/date_input_hint_controller.ts @@ -36,7 +36,7 @@ export class DateInputHintController extends ApplicationController { private translatePlaceholder() { const locale = document.documentElement.lang as 'fr' | 'en'; - const parts = PARTS[locale]; + const parts = PARTS[locale] ?? PARTS.fr; const example = new Date(2022, 9, 15).toLocaleDateString(); return [ Object.entries(parts).reduce( diff --git a/app/javascript/controllers/email_input_controller.ts b/app/javascript/controllers/email_input_controller.ts index 63fce7953..31849ceaa 100644 --- a/app/javascript/controllers/email_input_controller.ts +++ b/app/javascript/controllers/email_input_controller.ts @@ -1,11 +1,12 @@ -import { httpRequest } from '@utils'; -import { show, hide } from '@utils'; +import { hide, httpRequest, show } from '@utils'; import { ApplicationController } from './application_controller'; -type checkEmailResponse = { - success: boolean; - suggestions: string[]; -}; +type CheckEmailResponse = + | { + success: true; + suggestions: string[]; + } + | { success: false }; export class EmailInputController extends ApplicationController { static targets = ['ariaRegion', 'suggestion', 'input']; @@ -32,14 +33,17 @@ export class EmailInputController extends ApplicationController { const url = new URL(this.urlValue, document.baseURI); url.searchParams.append('email', this.inputTarget.value); - const data: checkEmailResponse | null = await httpRequest( - url.toString() - ).json(); + const data = await httpRequest(url.toString()) + .json() + .catch(() => null); - if (data && data.suggestions && data.suggestions.length > 0) { - this.suggestionTarget.innerHTML = data.suggestions[0]; - show(this.ariaRegionTarget); - this.ariaRegionTarget.focus(); + if (data?.success) { + const suggestion = data.suggestions.at(0); + if (suggestion) { + this.suggestionTarget.innerHTML = suggestion; + show(this.ariaRegionTarget); + this.ariaRegionTarget.focus(); + } } }