Skip to content
Merged
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
2 changes: 2 additions & 0 deletions client/src/domainTranslations.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export default {
defaultPageSize: 'מספר שורות בטבלה',
lateValue: 'שווי איחור',
phoneNumber: 'מספר טלפון',
mailAddressTitle: 'שם השולח',
mailAddressAlias: 'כתובת השולח',
yemotApiKey: 'מפתח API של Yemot',
managerPhone: 'טלפון מנהלת',
dashboardItems: 'הגדרות תמונת מצב',
Expand Down
1 change: 1 addition & 0 deletions client/src/roadmapFeatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export default [
{ html: 'עיצוב חדש לדוח המורות שדיווחו: כרטיס לכל כיתה עם שורה לכל שיעור, צביעת מספר החסרות וריבועי סיכום', status: 'בוצע', statusColor: 'success' },
{ html: 'דוח המורות שדיווחו: לחיצה על מספר החסרות מציגה את שמות הבנות שחסרו', status: 'בוצע', statusColor: 'success' },
{ html: 'דוח חדש "מעקב חיסורים": כרטיס לכל כיתה, סף חיסורים לבחירה, כמה חיסורים נשארו לכל תלמידה עד הסף ופירוט בלחיצה', status: 'בוצע', statusColor: 'success' },
{ html: 'מסך ההגדרות: הגדרת שם וכתובת השולח במיילים שנשלחים מהמערכת', status: 'בוצע', statusColor: 'success' },

// { html: 'הגדרת תקופת זמן לפי תאריכים', status: 'בקרוב', statusColor: 'warning' },
// { html: 'הגדרת תקופת זמן לפי יום בשבוע', status: 'בוצע', statusColor: 'success' },
Expand Down
35 changes: 35 additions & 0 deletions client/src/settings/MailSettingsInput.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { TextInput, maxLength, regex } from 'react-admin';
import { InputAdornment } from '@mui/material';
import { CommonSettingsAccordion } from '@shared/components/settings/CommonSettingsAccordion';

const MAIL_DOMAIN = 'mail.yoman.online';
const aliasValidate = regex(/^[a-zA-Z0-9._-]{3,64}$/, 'יש להשתמש באותיות באנגלית, מספרים, נקודה, מקף או קו תחתון (3-64 תווים)');

export function MailSettingsInput() {
return (
<CommonSettingsAccordion
id="mail-settings"
title="הגדרות מייל"
subtitle="שם וכתובת השולח במיילים שנשלחים מהמערכת"
>
<TextInput
source="mailAddressTitle"
label="resources.settings.fields.mailAddressTitle"
helperText="השם שיופיע לנמען כשולח המייל"
fullWidth
validate={maxLength(255)}
/>
<TextInput
source="mailAddressAlias"
label="resources.settings.fields.mailAddressAlias"
helperText="הכתובת ממנה יישלחו המיילים"
fullWidth
validate={aliasValidate}
InputProps={{
endAdornment: <InputAdornment position="end">@{MAIL_DOMAIN}</InputAdornment>,
}}
inputProps={{ dir: 'ltr' }}
/>
</CommonSettingsAccordion>
);
}
18 changes: 13 additions & 5 deletions client/src/settings/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { DashboardItemsInput } from '@shared/components/settings/DashboardItemsI
import { getLateValue, getDashboardItems, getReportStyles, getReportCardSettings, normalizeReportStyles } from './settingsUtil';
import { ReportStylesInput } from './ReportStylesInput';
import { GeneralSettingsInput } from './GeneralSettingsInput';
import { MailSettingsInput } from './MailSettingsInput';
import { ReportCardSettingsInput } from './ReportCardSettingsInput';
import { YemotSettingsInput } from '@shared/components/phone/YemotSettingsInput';
import { PhoneSettingsInput } from '@shared/components/phone/PhoneSettingsInput';
Expand All @@ -42,20 +43,26 @@ export default function Settings() {
reportStyles: normalizeReportStyles(getReportStyles(identity)),
reportCardSettings: getReportCardSettings(identity),
phoneNumber: identity?.phoneNumber ?? '',
mailAddressTitle: identity?.mailAddressTitle ?? '',
mailAddressAlias: identity?.mailAddressAlias ?? '',
};

const handleSave = async ({ phoneNumber, ...values }) => {
const handleSave = async ({ phoneNumber, mailAddressTitle, mailAddressAlias, ...values }) => {
try {
await dataProvider.updateSettings({ data: values });
if (phoneNumber !== (identity?.phoneNumber ?? '')) {
await dataProvider.updateProfile({ data: { phoneNumber } });
const profile = Object.fromEntries(
Object.entries({ phoneNumber, mailAddressTitle, mailAddressAlias })
.filter(([key, value]) => value !== (identity?.[key] ?? ''))
);
if (Object.keys(profile).length) {
await dataProvider.updateProfile({ data: profile });
}
await dataProvider.updateSettings({ data: values });
await authProvider.getIdentity(true);
notify('ההגדרות נשמרו בהצלחה', { type: 'info' });
navigate('/');
window.location.reload();
} catch (e) {
notify('שמירה נכשלה', { type: 'error' });
notify(e?.status === 400 && e?.message ? e.message : 'שמירה נכשלה', { type: 'error' });
}
};

Expand All @@ -66,6 +73,7 @@ export default function Settings() {
<ResourceContextProvider value="settings">
<SimpleForm onSubmit={handleSave} defaultValues={defaultValues} toolbar={<SettingsToolbar />}>
<GeneralSettingsInput />
<MailSettingsInput />
<ReportStylesInput />
<ReportCardSettingsInput />
<CommonSettingsAccordion
Expand Down
78 changes: 78 additions & 0 deletions client/src/settings/Settings.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import { AdminContext } from 'react-admin';
import Settings from './Settings';

jest.mock('./GeneralSettingsInput', () => ({ GeneralSettingsInput: () => null }));
jest.mock('./ReportStylesInput', () => ({ ReportStylesInput: () => null }));
jest.mock('./ReportCardSettingsInput', () => ({ ReportCardSettingsInput: () => null }));
jest.mock('./ManagerPhoneSettingsInput', () => ({ ManagerPhoneSettingsInput: () => null }));
jest.mock('@shared/components/phone/YemotSettingsInput', () => ({ YemotSettingsInput: () => null }));
jest.mock('@shared/components/phone/PhoneSettingsInput', () => ({ PhoneSettingsInput: () => null }));
jest.mock('@shared/components/settings/DashboardItemsInput', () => ({ DashboardItemsInput: () => null }));

const identity = {
id: 1,
fullName: 'test',
phoneNumber: '0500000000',
mailAddressTitle: 'Old School',
mailAddressAlias: 'old-school',
additionalData: {},
};

const authProvider = {
login: jest.fn(),
logout: jest.fn(),
checkAuth: jest.fn(() => Promise.resolve()),
checkError: jest.fn(() => Promise.resolve()),
getPermissions: jest.fn(() => Promise.resolve({})),
getIdentity: jest.fn(() => Promise.resolve(identity)),
};

const dataProvider = {
updateSettings: jest.fn(() => Promise.resolve({ success: true })),
updateProfile: jest.fn(() => Promise.resolve({ success: true })),
};

const originalLocation = window.location;

beforeEach(() => {
jest.clearAllMocks();
delete window.location;
window.location = { ...originalLocation, href: originalLocation.href, pathname: '/', search: '', hash: '', reload: jest.fn() };
});

afterAll(() => {
window.location = originalLocation;
});

test('sends only changed mail fields to updateProfile', async () => {
render(
<AdminContext dataProvider={dataProvider} authProvider={authProvider}>
<Settings />
</AdminContext>,
);

const titleInput = await screen.findByDisplayValue('Old School');
expect(screen.getByDisplayValue('old-school')).toBeInTheDocument();

fireEvent.change(titleInput, { target: { value: 'New School' } });
fireEvent.click(screen.getByRole('button', { name: /save|שמירה/i }));

await waitFor(() => expect(dataProvider.updateProfile).toHaveBeenCalledWith({ data: { mailAddressTitle: 'New School' } }));
expect(dataProvider.updateSettings).toHaveBeenCalled();
expect(dataProvider.updateSettings.mock.calls[0][0].data).not.toHaveProperty('mailAddressTitle');
});

test('skips updateProfile when no profile field changed', async () => {
render(
<AdminContext dataProvider={dataProvider} authProvider={authProvider}>
<Settings />
</AdminContext>,
);

await screen.findByDisplayValue('Old School');
fireEvent.click(screen.getByRole('button', { name: /save|שמירה/i }));

await waitFor(() => expect(dataProvider.updateSettings).toHaveBeenCalled());
expect(dataProvider.updateProfile).not.toHaveBeenCalled();
});
Loading