Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

custom_profile_fields: Refactor code for handling date type fields.

whilstsomebody30c6b35b957a
diff --git a/web/src/custom_profile_fields_ui.ts b/web/src/custom_profile_fields_ui.ts
index 0dd340407f7..63159dfec24 100644
--- a/web/src/custom_profile_fields_ui.ts
+++ b/web/src/custom_profile_fields_ui.ts
@@ -209,7 +209,11 @@ export function format_date(date: Date | undefined, format: string): string {
return flatpickr.formatDate(date, format);
}
-export function initialize_custom_date_type_fields(element_id: string, user_id: number): void {
+export function initialize_custom_date_type_fields(
+ element_id: string,
+ user_id: number,
+ for_profile_settings_panel = false,
+): void {
const $date_picker_elements = $(element_id).find(".custom_user_field .datepicker");
if ($date_picker_elements.length === 0) {
return;
@@ -224,7 +228,7 @@ export function initialize_custom_date_type_fields(element_id: string, user_id:
// our case it is a valid value when user does not want
// to set any value for the custom profile field.
if ($input_elem.parent().find(".date-field-alt-input").val() === "") {
- if (user_id !== people.my_current_user_id()) {
+ if (!for_profile_settings_panel) {
// For "Manage user" modal, API request is made after
// clicking on "Save changes" button.
return;
@@ -246,7 +250,7 @@ export function initialize_custom_date_type_fields(element_id: string, user_id:
);
const original_value = people.get_custom_profile_data(user_id, field_id)?.value ?? "";
instance.setDate(original_value);
- if (user_id !== people.my_current_user_id()) {
+ if (!for_profile_settings_panel) {
// Trigger "input" event so that save button state can
// be toggled in "Manage user" modal.
$input_elem
@@ -257,7 +261,7 @@ export function initialize_custom_date_type_fields(element_id: string, user_id:
return;
}
- if (user_id !== people.my_current_user_id()) {
+ if (!for_profile_settings_panel) {
// For "Manage user" modal, API request is made after
// clicking on "Save changes" button.
return;
diff --git a/web/src/settings_account.ts b/web/src/settings_account.ts
index 53b41430a36..279495086ac 100644
--- a/web/src/settings_account.ts
+++ b/web/src/settings_account.ts
@@ -236,6 +236,7 @@ export function add_custom_profile_fields_to_settings(): void {
custom_profile_fields_ui.initialize_custom_date_type_fields(
element_id,
people.my_current_user_id(),
+ true,
);
custom_profile_fields_ui.initialize_custom_pronouns_type_fields(element_id);
}