@micha.bigler/ui-core-micha 2.8.0 → 2.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,7 +3,6 @@ import React, { useEffect, useState } from 'react';
|
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
4
|
import Alert from '@mui/material/Alert';
|
|
5
5
|
import Box from '@mui/material/Box';
|
|
6
|
-
import Button from '@mui/material/Button';
|
|
7
6
|
import CircularProgress from '@mui/material/CircularProgress';
|
|
8
7
|
import Divider from '@mui/material/Divider';
|
|
9
8
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
@@ -143,6 +142,6 @@ export function NotificationSettings() {
|
|
|
143
142
|
if (loading) {
|
|
144
143
|
return _jsx(Box, { sx: { display: 'flex', justifyContent: 'center', py: 4 }, children: _jsx(CircularProgress, {}) });
|
|
145
144
|
}
|
|
146
|
-
return (_jsxs(Box, { sx: { maxWidth: 520 }, children: [_jsxs(Typography, { variant: "h6", gutterBottom: true, sx: { display: 'flex', alignItems: 'center', gap: 1 }, children: [_jsx(NotificationsIcon, {}), t('NotificationSettings.TITLE')] }), _jsx(Typography, { variant: "body2", color: "text.secondary", gutterBottom: true, children: t('NotificationSettings.SUBTITLE') }), error && _jsx(Alert, { severity: "error", sx: { mb: 2 }, onClose: () => setError(''), children: error }), conflict && _jsx(Alert, { severity: "warning", sx: { mb: 2 }, onClose: () => setConflict(''), children: conflict }), _jsx(Box, { sx: { py: 2 }, children: _jsx(FormControlLabel, { control: _jsx(Switch, { checked: Boolean(preferences === null || preferences === void 0 ? void 0 : preferences.email_opt_in), onChange: handleEmailToggle, disabled: savingEmail }), label: _jsxs(Box, { children: [_jsx(Typography, { variant: "body1", children: t('NotificationSettings.EMAIL_LABEL') }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('NotificationSettings.EMAIL_HINT') })] }), labelPlacement: "end", sx: { alignItems: 'flex-start', ml: 0 } }) }), _jsx(Divider, {}), _jsxs(Box, { sx: { py: 2 }, children: [
|
|
145
|
+
return (_jsxs(Box, { sx: { maxWidth: 520 }, children: [_jsxs(Typography, { variant: "h6", gutterBottom: true, sx: { display: 'flex', alignItems: 'center', gap: 1 }, children: [_jsx(NotificationsIcon, {}), t('NotificationSettings.TITLE')] }), _jsx(Typography, { variant: "body2", color: "text.secondary", gutterBottom: true, children: t('NotificationSettings.SUBTITLE') }), error && _jsx(Alert, { severity: "error", sx: { mb: 2 }, onClose: () => setError(''), children: error }), conflict && _jsx(Alert, { severity: "warning", sx: { mb: 2 }, onClose: () => setConflict(''), children: conflict }), _jsx(Box, { sx: { py: 2 }, children: _jsx(FormControlLabel, { control: _jsx(Switch, { checked: Boolean(preferences === null || preferences === void 0 ? void 0 : preferences.email_opt_in), onChange: handleEmailToggle, disabled: savingEmail }), label: _jsxs(Box, { children: [_jsx(Typography, { variant: "body1", children: t('NotificationSettings.EMAIL_LABEL') }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('NotificationSettings.EMAIL_HINT') })] }), labelPlacement: "end", sx: { alignItems: 'flex-start', ml: 0 } }) }), _jsx(Divider, {}), _jsxs(Box, { sx: { py: 2 }, children: [iosNeedsInstall && _jsx(Alert, { severity: "info", sx: { mb: 1.5 }, children: t('NotificationSettings.IOS_HINT') }), !pushSupported && !iosNeedsInstall && _jsx(Alert, { severity: "warning", sx: { mb: 1.5 }, children: t('NotificationSettings.PUSH_NOT_SUPPORTED') }), _jsx(FormControlLabel, { control: (_jsx(Switch, { checked: pushSubscribed, onChange: (event) => (event.target.checked ? handleEnablePush() : handleDisablePush()), disabled: savingPush || !pushSupported || iosNeedsInstall })), label: _jsxs(Box, { children: [_jsx(Typography, { variant: "body1", children: t('NotificationSettings.PUSH_LABEL') }), _jsx(Typography, { variant: "caption", color: "text.secondary", children: t('NotificationSettings.PUSH_HINT') })] }), labelPlacement: "end", sx: { alignItems: 'flex-start', ml: 0 } })] })] }));
|
|
147
146
|
}
|
|
148
147
|
export default NotificationSettings;
|
package/package.json
CHANGED
|
@@ -2,7 +2,6 @@ import React, { useEffect, useState } from 'react';
|
|
|
2
2
|
import { useTranslation } from 'react-i18next';
|
|
3
3
|
import Alert from '@mui/material/Alert';
|
|
4
4
|
import Box from '@mui/material/Box';
|
|
5
|
-
import Button from '@mui/material/Button';
|
|
6
5
|
import CircularProgress from '@mui/material/CircularProgress';
|
|
7
6
|
import Divider from '@mui/material/Divider';
|
|
8
7
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
@@ -172,15 +171,20 @@ export function NotificationSettings() {
|
|
|
172
171
|
<Divider />
|
|
173
172
|
|
|
174
173
|
<Box sx={{ py: 2 }}>
|
|
175
|
-
<Typography variant="body1" gutterBottom>{t('NotificationSettings.PUSH_LABEL')}</Typography>
|
|
176
|
-
<Typography variant="caption" color="text.secondary" display="block" sx={{ mb: 1.5 }}>{t('NotificationSettings.PUSH_HINT')}</Typography>
|
|
177
174
|
{iosNeedsInstall && <Alert severity="info" sx={{ mb: 1.5 }}>{t('NotificationSettings.IOS_HINT')}</Alert>}
|
|
178
|
-
{!pushSupported && !iosNeedsInstall && <Alert severity="warning">{t('NotificationSettings.PUSH_NOT_SUPPORTED')}</Alert>}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
175
|
+
{!pushSupported && !iosNeedsInstall && <Alert severity="warning" sx={{ mb: 1.5 }}>{t('NotificationSettings.PUSH_NOT_SUPPORTED')}</Alert>}
|
|
176
|
+
<FormControlLabel
|
|
177
|
+
control={(
|
|
178
|
+
<Switch
|
|
179
|
+
checked={pushSubscribed}
|
|
180
|
+
onChange={(event) => (event.target.checked ? handleEnablePush() : handleDisablePush())}
|
|
181
|
+
disabled={savingPush || !pushSupported || iosNeedsInstall}
|
|
182
|
+
/>
|
|
183
|
+
)}
|
|
184
|
+
label={<Box><Typography variant="body1">{t('NotificationSettings.PUSH_LABEL')}</Typography><Typography variant="caption" color="text.secondary">{t('NotificationSettings.PUSH_HINT')}</Typography></Box>}
|
|
185
|
+
labelPlacement="end"
|
|
186
|
+
sx={{ alignItems: 'flex-start', ml: 0 }}
|
|
187
|
+
/>
|
|
184
188
|
</Box>
|
|
185
189
|
</Box>
|
|
186
190
|
);
|
|
@@ -49,7 +49,7 @@ describe('NotificationSettings push toggle', () => {
|
|
|
49
49
|
vi.stubGlobal('Notification', { requestPermission: vi.fn().mockResolvedValue('granted') });
|
|
50
50
|
|
|
51
51
|
render(<NotificationSettings />);
|
|
52
|
-
fireEvent.click(await screen.findByRole('
|
|
52
|
+
fireEvent.click(await screen.findByRole('switch', { name: /PUSH_LABEL/ }));
|
|
53
53
|
|
|
54
54
|
await waitFor(() => expect(notificationsApi.patchNotificationPreferences).toHaveBeenCalledWith({ push_opt_in: true }));
|
|
55
55
|
expect(Notification.requestPermission).toHaveBeenCalledOnce();
|
|
@@ -73,7 +73,7 @@ describe('NotificationSettings push toggle', () => {
|
|
|
73
73
|
installPushEnvironment(subscription);
|
|
74
74
|
|
|
75
75
|
render(<NotificationSettings />);
|
|
76
|
-
fireEvent.click(await screen.findByRole('
|
|
76
|
+
fireEvent.click(await screen.findByRole('switch', { name: /PUSH_LABEL/ }));
|
|
77
77
|
|
|
78
78
|
await waitFor(() => expect(subscription.unsubscribe).toHaveBeenCalledOnce());
|
|
79
79
|
expect(notificationsApi.removePushSubscription).toHaveBeenCalledWith({ endpoint: subscription.endpoint });
|