-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1107 from Quetzacoalt91/add-error-404
Introduce Error 404 page
- Loading branch information
Showing
28 changed files
with
527 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import DomLifecycle from '../types/DomLifecycle'; | ||
import ErrorPage404 from './error/ErrorPage404'; | ||
import PageAbstract from './PageAbstract'; | ||
|
||
export default class ErrorPage extends PageAbstract { | ||
errorPage?: DomLifecycle; | ||
|
||
constructor() { | ||
super(); | ||
|
||
if (document.getElementById('ua_error_404')) { | ||
this.errorPage = new ErrorPage404(); | ||
} | ||
} | ||
|
||
public mount = (): void => { | ||
this.errorPage?.mount(); | ||
}; | ||
|
||
public beforeDestroy = (): void => { | ||
this.errorPage?.beforeDestroy(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import api from '../../api/RequestHandler'; | ||
import DomLifecycle from '../../types/DomLifecycle'; | ||
|
||
export default class ErrorPage404 implements DomLifecycle { | ||
isOnHomePage: boolean = false; | ||
|
||
public constructor() { | ||
this.isOnHomePage = new URLSearchParams(window.location.search).get('route') === 'home-page'; | ||
} | ||
|
||
public mount = (): void => { | ||
this.#activeActionButton.classList.remove('hidden'); | ||
this.#form.addEventListener('submit', this.#onSubmit); | ||
}; | ||
|
||
public beforeDestroy = (): void => { | ||
this.#form.removeEventListener('submit', this.#onSubmit); | ||
}; | ||
|
||
get #activeActionButton(): HTMLFormElement | HTMLAnchorElement { | ||
return this.isOnHomePage ? this.#exitButton : this.#form; | ||
} | ||
|
||
get #form(): HTMLFormElement { | ||
const form = document.forms.namedItem('home-page-form'); | ||
if (!form) { | ||
throw new Error('Form not found'); | ||
} | ||
|
||
['routeToSubmit'].forEach((data) => { | ||
if (!form.dataset[data]) { | ||
throw new Error(`Missing data ${data} from form dataset.`); | ||
} | ||
}); | ||
|
||
return form; | ||
} | ||
|
||
get #exitButton(): HTMLAnchorElement { | ||
const link = document.getElementById('exit-button'); | ||
|
||
if (!link || !(link instanceof HTMLAnchorElement)) { | ||
throw new Error('Link is not found or invalid'); | ||
} | ||
return link; | ||
} | ||
|
||
readonly #onSubmit = async (event: Event): Promise<void> => { | ||
event.preventDefault(); | ||
|
||
await api.post(this.#form.dataset.routeToSubmit!, new FormData(this.#form)); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,4 +67,7 @@ class Routes | |
|
||
/* logs */ | ||
const DOWNLOAD_LOGS = 'download-logs'; | ||
|
||
/* errors */ | ||
const ERROR_404 = 'error-404'; | ||
} |
Oops, something went wrong.