Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions assets/src/js/frontend/dashboard/pages/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ interface PreferencesFormProps {
auto_play_next: boolean;
theme: string;
font_scale: number;
formId?: string;
}

interface UpdateNotificationProps {
[key: string]: boolean | string;
}

const settings = () => {
Expand Down Expand Up @@ -100,7 +105,8 @@ const settings = () => {
this.handleResetPassword = this.handleResetPassword.bind(this);

this.handleUpdateNotification = this.query.useMutation(this.updateNotification, {
onSuccess: (data: TutorMutationResponse<string>) => {
onSuccess: (data: TutorMutationResponse<string>, payload: UpdateNotificationProps) => {
this.form.reset(payload?.formId as string, payload as unknown as Record<string, unknown>);
this.toast.success(data?.message ?? __('Notification settings updated', 'tutor'));
},
onError: (error: Error) => {
Expand Down Expand Up @@ -168,7 +174,8 @@ const settings = () => {
});

this.savePreferencesMutation = this.query.useMutation(this.updatePreferences, {
onSuccess: (data: TutorMutationResponse<PreferencesFormProps>) => {
onSuccess: (data: TutorMutationResponse<PreferencesFormProps>, payload: PreferencesFormProps) => {
this.form.reset(payload?.formId || '', payload as unknown as Record<string, unknown>);
this.toast.success(data?.message ?? __('Preferences saved successfully', 'tutor'));
},
onError: (error: Error) => {
Expand All @@ -177,16 +184,22 @@ const settings = () => {
});
},

async updatePreferences(payload: Record<string, unknown>) {
async updatePreferences(payload: PreferencesFormProps) {
return wpAjaxInstance.post(endpoints.UPDATE_USER_PREFERENCES, payload) as unknown as Promise<
TutorMutationResponse<PreferencesFormProps>
>;
},

async updateNotification(payload: Record<string, boolean>) {
async updateNotification(payload: UpdateNotificationProps) {
const transformedPayload = Object.keys(payload).reduce(
(formattedPayload, key) => {
const value = payload[key];

if (typeof value !== 'boolean') {
formattedPayload[`${key}`] = value;
return formattedPayload;
}

const stringValue = typeof value === 'boolean' ? (value ? 'on' : 'off') : value;

if (!key.includes('__')) {
Expand Down
8 changes: 0 additions & 8 deletions assets/src/scss/frontend/dashboard/settings/_profile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,6 @@ body:has(#wpadminbar) {
}
}

.tutor-profile-notification-content {
border-top: 1px solid $tutor-border-idle;
}

.tutor-profile-notification-toggle {
display: flex;
align-items: center;
Expand Down Expand Up @@ -142,8 +138,4 @@ body:has(#wpadminbar) {
.tutor-input-field {
margin-bottom: 0px;
}

.tutor-profile-notification-content {
border-top: 1px solid $tutor-border-idle;
}
}
19 changes: 5 additions & 14 deletions templates/dashboard/account/settings/preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@
use Tutor\Components\Constants\InputType;
use Tutor\Components\Constants\Size;

// Theme options.
$theme_options = UserPreference::get_theme_options();

$font_scale_options = UserPreference::get_font_scale_options();

// Load current user preferences to seed the form.
$user_preferences = ( new UserPreference( false ) )->get_preferences();

$autoload_course_content = (bool) tutor_utils()->get_option( 'autoload_next_course_content' );

$default_values = array(
'auto_play_next' => isset( $user_preferences['auto_play_next'] ) ? (bool) $user_preferences['auto_play_next'] : false,
'auto_play_next' => isset( $user_preferences['auto_play_next'] ) ? (bool) $user_preferences['auto_play_next'] : $autoload_course_content,
'theme' => isset( $user_preferences['theme'] ) ? $user_preferences['theme'] : UserPreference::DEFAULT_THEME,
'font_scale' => isset( $user_preferences['font_scale'] ) ? (int) $user_preferences['font_scale'] : UserPreference::DEFAULT_FONT_SCALE,
);
Expand All @@ -41,13 +42,12 @@
shouldFocusError: true,
defaultValues: <?php echo wp_json_encode( $default_values ); ?>
})'

x-bind="getFormBindings()"
@submit="handleSubmit((data) => { savePreferencesMutation?.mutate(data); })($event)"
@submit="handleSubmit((data) => { savePreferencesMutation?.mutate({...data, formId: '<?php echo esc_attr( $form_id ); ?>'}); })($event)"
>
<!-- Course Content Section -->
<h5 class="tutor-preferences-section-header tutor-h5">
<?php esc_html_e( 'Course Content', 'tutor' ); ?>
<?php esc_html_e( 'Preferences', 'tutor' ); ?>
</h5>
<div class="tutor-card tutor-card-rounded-2xl tutor-mb-7">
<div class="tutor-preferences-setting-item">
Expand All @@ -68,11 +68,6 @@
?>
</div>
</div>
</div>

<!-- Appearance Section -->
<h5 class="tutor-preferences-section-header tutor-color-black tutor-mb-7"><?php esc_html_e( 'Appearance', 'tutor' ); ?></h5>
<div class="tutor-card tutor-card-rounded-2xl tutor-mb-6">
<div class="tutor-preferences-setting-item">
<div class="tutor-preferences-setting-content">
<div class="tutor-preferences-setting-icon">
Expand All @@ -95,10 +90,6 @@
?>
</div>
</div>
</div>

<h5 class="tutor-preferences-section-header tutor-color-black tutor-mb-7"><?php esc_html_e( 'Accessibility', 'tutor' ); ?></h5>
<div class="tutor-card tutor-card-rounded-2xl tutor-mb-6">
<div class="tutor-preferences-setting-item">
<div class="tutor-preferences-setting-content">
<div class="tutor-preferences-setting-icon">
Expand Down
Loading