(fix):update user profile toast
This commit is contained in:
@@ -419,13 +419,6 @@
|
||||
background: none;
|
||||
border: none;
|
||||
}
|
||||
.profile-form__submit-msg {
|
||||
font-size: 14px;
|
||||
color: var(--color-ink-3);
|
||||
}
|
||||
.profile-form__submit-msg.is-error {
|
||||
color: var(--color-error);
|
||||
}
|
||||
.profile-add-contact {
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
@@ -449,10 +449,6 @@
|
||||
color: var(--color-error);
|
||||
}
|
||||
|
||||
/* ---- 保存反馈 ---- */
|
||||
#profile-save-msg.success { color: var(--color-success); }
|
||||
#profile-save-msg.error { color: var(--color-error); }
|
||||
|
||||
/* ==================== 账号设置区 ==================== */
|
||||
.settings-section {
|
||||
margin-bottom: 20px;
|
||||
|
||||
@@ -261,43 +261,49 @@
|
||||
/* ==================== 个人信息保存 ==================== */
|
||||
|
||||
|
||||
function initProfileForm() {
|
||||
var form = document.getElementById('profile-form');
|
||||
function initProfileForm(root) {
|
||||
root = root || document;
|
||||
var form = root.id === 'profile-form' ? root : root.querySelector('#profile-form');
|
||||
if (!form) return;
|
||||
if (form.dataset.aksrtProfileInitialized === 'true') return;
|
||||
form.dataset.aksrtProfileInitialized = 'true';
|
||||
|
||||
form.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
var btn = document.getElementById('profile-save-btn');
|
||||
var msg = document.getElementById('profile-save-msg');
|
||||
var btn = form.querySelector('#profile-save-btn');
|
||||
if (!btn || btn.disabled) return;
|
||||
btn.disabled = true;
|
||||
btn.textContent = i18n.saving || '保存中…';
|
||||
msg.className = 'profile-form__submit-msg';
|
||||
msg.textContent = '';
|
||||
notyf(i18n.saving || '正在保存资料…', 'load', '', 'aksrt-profile-save-toast');
|
||||
|
||||
var data = new FormData(form);
|
||||
data.append('user_id', String(userId));
|
||||
data.set('user_id', String(userId));
|
||||
|
||||
fetch(ajaxUrl, { method: 'POST', body: data })
|
||||
fetch(ajaxUrl, { method: 'POST', credentials: 'same-origin', body: data })
|
||||
.then(function(r) { return r.json(); })
|
||||
.then(function(res) {
|
||||
btn.disabled = false;
|
||||
btn.textContent = i18n.saveBtn || '保存修改';
|
||||
if (res.success) {
|
||||
notyf(i18n.saved || '已保存');
|
||||
notyf((res.data && res.data.message) || i18n.saved || '保存成功!', 'success', 5, 'aksrt-profile-save-toast');
|
||||
} else {
|
||||
msg.className = 'profile-form__submit-msg is-error';
|
||||
msg.textContent = res.data.message || (i18n.saveFailed || '保存失败');
|
||||
notyf((res.data && res.data.message) || i18n.saveFailed || '保存失败', 'danger', 5, 'aksrt-profile-save-toast');
|
||||
}
|
||||
})
|
||||
.catch(function() {
|
||||
btn.disabled = false;
|
||||
btn.textContent = i18n.saveBtn || '保存修改';
|
||||
msg.className = 'profile-form__submit-msg is-error';
|
||||
msg.textContent = i18n.networkError || '网络错误,请重试';
|
||||
notyf(i18n.networkError || '网络错误,请重试', 'danger', 5, 'aksrt-profile-save-toast');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if (window.AksrtFrontend && typeof window.AksrtFrontend.register === 'function') {
|
||||
window.AksrtFrontend.register('aksrt-profile-form', function(root) {
|
||||
initProfileForm(root);
|
||||
});
|
||||
}
|
||||
|
||||
function initAuthForm() {
|
||||
var root = document.querySelector('[data-identity-root]');
|
||||
if (root && window.AKSRTUserCenterAuth && typeof window.AKSRTUserCenterAuth.init === 'function') {
|
||||
|
||||
@@ -64,6 +64,5 @@ $profile_details = isset($profile_details) && is_array($profile_details) ? $prof
|
||||
<button type="submit" class="btn-primary btn-lg" id="profile-save-btn">
|
||||
<?php esc_html_e('保存修改', 'aksrt'); ?>
|
||||
</button>
|
||||
<span id="profile-save-msg" class="profile-form__submit-msg"></span>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@@ -511,8 +511,8 @@ $hmb_js = get_template_directory() . '/assets/js/header-newadd.js';
|
||||
);
|
||||
}
|
||||
$user_center_deps = file_exists($identity_js)
|
||||
? ['aksrt-script', 'aksrt-route-user-center-auth']
|
||||
: ['aksrt-script'];
|
||||
? ['aksrt-script', 'aksrt-route-user-center-auth', 'aksrt-notyf']
|
||||
: ['aksrt-script', 'aksrt-notyf'];
|
||||
if ($has_orders_panel && wp_script_is('aksrt-order-center', 'registered')) {
|
||||
$user_center_deps[] = 'aksrt-order-center';
|
||||
}
|
||||
|
||||
@@ -17,22 +17,6 @@ if (!is_user_logged_in()) {
|
||||
}
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
$user_id = (int) $current_user->ID;
|
||||
|
||||
if ('POST' === ($_SERVER['REQUEST_METHOD'] ?? '') && isset($_POST['action']) && 'aksrt_save_profile' === sanitize_key(wp_unslash($_POST['action']))) {
|
||||
$nonce = isset($_POST['_profile_nonce']) ? sanitize_text_field(wp_unslash($_POST['_profile_nonce'])) : '';
|
||||
if (!wp_verify_nonce($nonce, 'aksrt_profile_save')) {
|
||||
$result = new WP_Error('aksrt_profile_nonce', __('安全验证失败,请刷新页面重试', 'aksrt'));
|
||||
} else {
|
||||
$result = aksrt_save_user_center_profile($user_id, $_POST);
|
||||
}
|
||||
|
||||
$redirect_args = is_wp_error($result)
|
||||
? ['profile_error' => $result->get_error_message()]
|
||||
: ['saved' => '1'];
|
||||
wp_safe_redirect(add_query_arg($redirect_args, aksrt_get_user_center_tab_url('profile')));
|
||||
exit;
|
||||
}
|
||||
|
||||
$render_context = aksrt_get_user_center_render_context($current_user);
|
||||
|
||||
@@ -49,11 +33,6 @@ get_header();
|
||||
</aside>
|
||||
<div class="user-center-content uc-content">
|
||||
<div class="uc-drawer-overlay" id="uc-drawer-overlay"></div>
|
||||
<?php if (isset($_GET['saved'])) : ?>
|
||||
<div class="aksrt-user-center__notice" role="status"><?php esc_html_e('个人资料已保存', 'aksrt'); ?></div>
|
||||
<?php elseif (isset($_GET['profile_error'])) : ?>
|
||||
<div class="aksrt-user-center__notice aksrt-user-center__notice--error" role="alert"><?php echo esc_html(wp_unslash($_GET['profile_error'])); ?></div>
|
||||
<?php endif; ?>
|
||||
<?php get_template_part('templates/parts/user-center/mobile-tabs', null, ['context' => $render_context]); ?>
|
||||
<?php foreach ($render_context['panels'] as $panel) : ?>
|
||||
<?php get_template_part('templates/parts/user-center/panel', null, ['panel' => $panel]); ?>
|
||||
|
||||
@@ -259,6 +259,26 @@ test('VIP purchase and points exchange use direct fixed-id notyf flows', () => {
|
||||
assert.match(scripts, /'aksrt-pay-vip',[\s\S]*?\/assets\/js\/pay-vip\.js',[\s\S]*?\[[^\]]*'aksrt-notyf'[^\]]*\]/);
|
||||
});
|
||||
|
||||
test('profile save uses AJAX rehydrate and a fixed-id notyf flow without query feedback', () => {
|
||||
const profile = read('assets/js/routes/user-center.js');
|
||||
const page = read('templates/pages/page-profile.php');
|
||||
const form = read('inc/helpers/user-center-renderers/profile-form.php');
|
||||
const layout = read('assets/css/routes/profile/layout.css');
|
||||
const lists = read('assets/css/routes/profile/lists.css');
|
||||
const scripts = read('src/Core/ScriptsPart1b.php');
|
||||
|
||||
assert.match(profile, /function initProfileForm\(root\)[\s\S]*?aksrtProfileInitialized[\s\S]*?addEventListener\('submit'/);
|
||||
assert.match(profile, /register\('aksrt-profile-form',[\s\S]*?initProfileForm\(root\)/);
|
||||
assert.match(profile, /notyf\([^;]+?'load'[^;]+?'aksrt-profile-save-toast'\);/);
|
||||
assert.match(profile, /notyf\([^;]+?'success'[^;]+?'aksrt-profile-save-toast'\);/);
|
||||
assert.match(profile, /notyf\([^;]+?'danger'[^;]+?'aksrt-profile-save-toast'\);/);
|
||||
assert.match(profile, /fetch\(ajaxUrl, \{ method: 'POST', credentials: 'same-origin', body: data \}\)/);
|
||||
assert.match(scripts, /\$user_center_deps[\s\S]*?\[[^\]]*'aksrt-notyf'[^\]]*\][\s\S]*?\/assets\/js\/routes\/user-center\.js/);
|
||||
|
||||
assert.doesNotMatch(page, /REQUEST_METHOD|profile_error|['"]saved['"]|add_query_arg/);
|
||||
assert.doesNotMatch([profile, form, layout, lists].join('\n'), /profile-save-msg|profile-form__submit-msg/);
|
||||
});
|
||||
|
||||
test('legacy frontend toast APIs and selectors are fully removed', () => {
|
||||
const files = [
|
||||
'assets/js',
|
||||
|
||||
Reference in New Issue
Block a user