diff --git a/assets/src/js/frontend/dashboard/pages/settings.ts b/assets/src/js/frontend/dashboard/pages/settings.ts index d08863c31a..219863b3f9 100644 --- a/assets/src/js/frontend/dashboard/pages/settings.ts +++ b/assets/src/js/frontend/dashboard/pages/settings.ts @@ -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 = () => { @@ -100,7 +105,8 @@ const settings = () => { this.handleResetPassword = this.handleResetPassword.bind(this); this.handleUpdateNotification = this.query.useMutation(this.updateNotification, { - onSuccess: (data: TutorMutationResponse) => { + onSuccess: (data: TutorMutationResponse, payload: UpdateNotificationProps) => { + this.form.reset(payload?.formId as string, payload as unknown as Record); this.toast.success(data?.message ?? __('Notification settings updated', 'tutor')); }, onError: (error: Error) => { @@ -168,7 +174,8 @@ const settings = () => { }); this.savePreferencesMutation = this.query.useMutation(this.updatePreferences, { - onSuccess: (data: TutorMutationResponse) => { + onSuccess: (data: TutorMutationResponse, payload: PreferencesFormProps) => { + this.form.reset(payload?.formId || '', payload as unknown as Record); this.toast.success(data?.message ?? __('Preferences saved successfully', 'tutor')); }, onError: (error: Error) => { @@ -177,16 +184,22 @@ const settings = () => { }); }, - async updatePreferences(payload: Record) { + async updatePreferences(payload: PreferencesFormProps) { return wpAjaxInstance.post(endpoints.UPDATE_USER_PREFERENCES, payload) as unknown as Promise< TutorMutationResponse >; }, - async updateNotification(payload: Record) { + 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('__')) { diff --git a/assets/src/scss/frontend/dashboard/settings/_profile.scss b/assets/src/scss/frontend/dashboard/settings/_profile.scss index 7107a7b8d0..34bcd2f303 100644 --- a/assets/src/scss/frontend/dashboard/settings/_profile.scss +++ b/assets/src/scss/frontend/dashboard/settings/_profile.scss @@ -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; @@ -142,8 +138,4 @@ body:has(#wpadminbar) { .tutor-input-field { margin-bottom: 0px; } - - .tutor-profile-notification-content { - border-top: 1px solid $tutor-border-idle; - } } diff --git a/templates/dashboard/account/settings/preferences.php b/templates/dashboard/account/settings/preferences.php index aa3cb4dee0..c620ff4834 100644 --- a/templates/dashboard/account/settings/preferences.php +++ b/templates/dashboard/account/settings/preferences.php @@ -16,7 +16,6 @@ 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(); @@ -24,8 +23,10 @@ // 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, ); @@ -41,13 +42,12 @@ shouldFocusError: true, defaultValues: })' - x-bind="getFormBindings()" - @submit="handleSubmit((data) => { savePreferencesMutation?.mutate(data); })($event)" + @submit="handleSubmit((data) => { savePreferencesMutation?.mutate({...data, formId: ''}); })($event)" >
- +
@@ -68,11 +68,6 @@ ?>
- - - -
-
@@ -95,10 +90,6 @@ ?>
-
- -
-