-
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.
Introduce page to display in case of HTTP 404
- Loading branch information
1 parent
aeeee3d
commit 8ae36dc
Showing
13 changed files
with
386 additions
and
75 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
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 = () => { | ||
this.errorPage?.mount(); | ||
}; | ||
|
||
public beforeDestroy = () => { | ||
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 = () => { | ||
this.#activeActionButton.classList.remove('hidden'); | ||
this.#form.addEventListener('submit', this.#onSubmit); | ||
}; | ||
|
||
public beforeDestroy = () => { | ||
this.#form.removeEventListener('submit', this.#onSubmit); | ||
}; | ||
|
||
get #activeActionButton(): HTMLFormElement | HTMLAnchorElement { | ||
return this.isOnHomePage ? this.#form : this.#exitButton; | ||
} | ||
|
||
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) => { | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
|
||
namespace PrestaShop\Module\AutoUpgrade\Router; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class UrlGenerator | ||
{ | ||
/** @var string */ | ||
private $shopBasePath; | ||
/** @var string */ | ||
private $adminFolder; | ||
|
||
public function __construct(string $shopBasePath, string $adminFolder) | ||
{ | ||
$this->shopBasePath = $shopBasePath; | ||
$this->adminFolder = $adminFolder; | ||
} | ||
|
||
public function getShopAbsolutePathFromRequest(Request $request): string | ||
{ | ||
// Determine the subdirectories of the PHP entry point (the script being executed) | ||
// relative to the shop root folder. | ||
// This calculation helps generate a base path that correctly accounts for any subfolder in which | ||
// the shop might be installed. | ||
$subDirs = explode( | ||
DIRECTORY_SEPARATOR, | ||
trim( | ||
str_replace( | ||
$this->shopBasePath, | ||
'', | ||
dirname($request->server->get('SCRIPT_FILENAME', '') | ||
) | ||
), DIRECTORY_SEPARATOR) | ||
); | ||
$numberOfSubDirs = count($subDirs); | ||
|
||
$path = explode('/', $request->getBasePath()); | ||
|
||
$path = array_splice($path, 0, -$numberOfSubDirs); | ||
|
||
return implode('/', $path) ?: '/'; | ||
} | ||
|
||
public function getShopAdminAbsolutePathFromRequest(Request $request): string | ||
{ | ||
return rtrim($this->getShopAbsolutePathFromRequest($request), '/') . '/' . $this->adminFolder; | ||
} | ||
} |
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
Oops, something went wrong.