-
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 #976 from Quetzacoalt91/update-options-page
[NEW UI] Update options page
- Loading branch information
Showing
21 changed files
with
248 additions
and
77 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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
beforeAll(() => { | ||
window.AutoUpgradeVariables = { | ||
token: 'test-token', | ||
admin_url: 'http://localhost', | ||
admin_dir: '/admin_directory', | ||
stepper_parent_id: 'stepper_content' | ||
}; | ||
}); | ||
// We don't wait for the call to beforeAll to define window properties. | ||
window.AutoUpgradeVariables = { | ||
token: 'test-token', | ||
admin_url: 'http://localhost', | ||
admin_dir: '/admin_directory', | ||
stepper_parent_id: 'stepper_content' | ||
}; | ||
|
||
beforeAll(() => {}); |
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 |
---|---|---|
@@ -1,13 +1,51 @@ | ||
import UpdatePage from './UpdatePage'; | ||
import api from '../api/RequestHandler'; | ||
|
||
export default class UpdatePageUpdateOptions extends UpdatePage { | ||
protected stepCode = 'update-options'; | ||
|
||
constructor() { | ||
super(); | ||
} | ||
|
||
public mount() { | ||
this.initStepper(); | ||
this.form.addEventListener('submit', this.onSubmit); | ||
this.form.addEventListener('change', this.onChange); | ||
} | ||
|
||
public beforeDestroy() { | ||
try { | ||
this.form.removeEventListener('submit', this.onSubmit); | ||
this.form.removeEventListener('change', this.onChange); | ||
} catch { | ||
// Do Nothing, page is likely removed from the DOM already | ||
} | ||
} | ||
|
||
private get form(): HTMLFormElement { | ||
const form = document.forms.namedItem('update-options-page-form'); | ||
if (!form) { | ||
throw new Error('Form not found'); | ||
} | ||
|
||
['routeToSave', 'routeToSubmit'].forEach((data) => { | ||
if (!form.dataset[data]) { | ||
throw new Error(`Missing data ${data} from form dataset.`); | ||
} | ||
}); | ||
|
||
return form; | ||
} | ||
|
||
private readonly onChange = async (ev: Event) => { | ||
const optionInput = ev.target as HTMLInputElement; | ||
|
||
const data = new FormData(this.form); | ||
optionInput.setAttribute('disabled', 'true'); | ||
await api.post(this.form.dataset.routeToSave!, data); | ||
optionInput.removeAttribute('disabled'); | ||
}; | ||
|
||
private 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
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,25 @@ | ||
<?php | ||
|
||
namespace PrestaShop\Module\AutoUpgrade\Twig; | ||
|
||
abstract class ValidatorToFormFormater | ||
{ | ||
/** | ||
* @param array<array{message:string, target?:string}> $errors | ||
* | ||
* @return array<'global'|string, string> | ||
*/ | ||
public static function format($errors): array | ||
{ | ||
return array_column( | ||
array_map(function ($error) { | ||
return [ | ||
'key' => $error['target'] ?? 'global', | ||
'value' => $error['message'], | ||
]; | ||
}, $errors), | ||
'value', | ||
'key' | ||
); | ||
} | ||
} |
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
Oops, something went wrong.