Skip to content

feat: redesign settings ux #947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 2, 2024
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
4 changes: 2 additions & 2 deletions src/__mocks__/mock-state.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Appearance, AuthState, SettingsState } from '../types';
import { Theme, AuthState, SettingsState } from '../types';
import { mockedUser, mockedEnterpriseAccounts } from './mockedData';

export const mockAccounts: AuthState = {
Expand All @@ -13,7 +13,7 @@ export const mockSettings: SettingsState = {
showNotifications: true,
showBots: true,
openAtStartup: false,
appearance: Appearance.SYSTEM,
theme: Theme.SYSTEM,
colors: false,
markAsDoneOnOpen: false,
};
4 changes: 2 additions & 2 deletions src/components/fields/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ export const FieldCheckbox = (props: IFieldCheckbox) => {
{props.label}
</label>
{props.placeholder && (
<p className="text-gray-500 dark:text-gray-300">
<div className="italic text-gray-500 dark:text-gray-300">
{props.placeholder}
</p>
</div>
)}
</div>
</div>
Expand Down
24 changes: 16 additions & 8 deletions src/components/fields/RadioGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,31 @@ export const FieldRadioGroup = ({
value: string;
}) => {
return (
<fieldset id={name} className="mb-1">
<div>
<legend className="mb-1 text-base font-medium dark:text-white">
<div className="flex items-start mt-1 mb-3">
<div className="mr-3 text-sm py-1">
<label
htmlFor={name}
className="font-medium text-gray-700 dark:text-gray-200 "
>
{label}
</legend>
{placeholder && <p className="text-sm text-gray-500">{placeholder}</p>}
</label>

{placeholder && (
<div className="italic text-gray-500 dark:text-gray-300">
{placeholder}
</div>
)}
</div>

<div
className="flex items-center space-x-4 py-2"
className="flex items-center space-x-4"
role="group"
aria-labelledby={name}
>
{options.map((item) => {
return (
<div
className="flex items-center mt-1"
className="flex mt-1"
key={`radio_item_${item.value.toLowerCase()}`}
>
<input
Expand All @@ -55,6 +63,6 @@ export const FieldRadioGroup = ({
);
})}
</div>
</fieldset>
</div>
);
};
30 changes: 16 additions & 14 deletions src/components/fields/__snapshots__/RadioGroup.test.tsx.snap
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`components/fields/radiogroup.tsx should render 1`] = `
<fieldset
className="mb-1"
id="appearance"
<div
className="flex items-start mt-1 mb-3"
>
<div>
<legend
className="mb-1 text-base font-medium dark:text-white"
<div
className="mr-3 text-sm py-1"
>
<label
className="font-medium text-gray-700 dark:text-gray-200 "
htmlFor="appearance"
>
Appearance
</legend>
<p
className="text-sm text-gray-500"
</label>
<div
className="italic text-gray-500 dark:text-gray-300"
>
This is some helper text
</p>
</div>
</div>
<div
aria-labelledby="appearance"
className="flex items-center space-x-4 py-2"
className="flex items-center space-x-4"
role="group"
>
<div
className="flex items-center mt-1"
className="flex mt-1"
>
<input
checked={false}
Expand All @@ -42,7 +44,7 @@ exports[`components/fields/radiogroup.tsx should render 1`] = `
</label>
</div>
<div
className="flex items-center mt-1"
className="flex mt-1"
>
<input
checked={true}
Expand All @@ -61,5 +63,5 @@ exports[`components/fields/radiogroup.tsx should render 1`] = `
</label>
</div>
</div>
</fieldset>
</div>
`;
4 changes: 2 additions & 2 deletions src/context/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ describe('context/App.tsx', () => {
expect(saveStateMock).toHaveBeenCalledWith(
{ enterpriseAccounts: [], token: null, user: null },
{
appearance: 'SYSTEM',
theme: 'SYSTEM',
openAtStartup: false,
participating: true,
playSound: true,
Expand Down Expand Up @@ -324,7 +324,7 @@ describe('context/App.tsx', () => {
expect(saveStateMock).toHaveBeenCalledWith(
{ enterpriseAccounts: [], token: null, user: null },
{
appearance: 'SYSTEM',
theme: 'SYSTEM',
openAtStartup: true,
participating: false,
playSound: true,
Expand Down
12 changes: 6 additions & 6 deletions src/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { useInterval } from '../hooks/useInterval';
import { useNotifications } from '../hooks/useNotifications';
import {
AccountNotifications,
Appearance,
Theme,
AuthOptions,
AuthState,
AuthTokenOptions,
SettingsState,
} from '../types';
import { apiRequestAuth } from '../utils/api-requests';
import { setAppearance } from '../utils/appearance';
import { setTheme } from '../utils/theme';
import { addAccount, authGitHub, getToken, getUserData } from '../utils/auth';
import { setAutoLaunch } from '../utils/comms';
import Constants from '../utils/constants';
Expand All @@ -36,7 +36,7 @@ export const defaultSettings: SettingsState = {
showNotifications: true,
showBots: true,
openAtStartup: false,
appearance: Appearance.SYSTEM,
theme: Theme.SYSTEM,
colors: null,
markAsDoneOnOpen: false,
};
Expand Down Expand Up @@ -87,8 +87,8 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
}, []);

useEffect(() => {
setAppearance(settings.appearance as Appearance);
}, [settings.appearance]);
setTheme(settings.theme as Theme);
}, [settings.theme]);

useEffect(() => {
fetchNotifications(accounts, settings);
Expand All @@ -103,7 +103,7 @@ export const AppProvider = ({ children }: { children: React.ReactNode }) => {
}, 60000);

const updateSetting = useCallback(
(name: keyof SettingsState, value: boolean | Appearance) => {
(name: keyof SettingsState, value: boolean | Theme) => {
if (name === 'openAtStartup') {
setAutoLaunch(value as boolean);
}
Expand Down
4 changes: 2 additions & 2 deletions src/routes/Settings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ describe('routes/Settings.tsx', () => {
expect(updateSetting).toHaveBeenCalledWith('openAtStartup', false);
});

it('should change the appearance radio group', async () => {
it('should change the theme radio group', async () => {
let getByLabelText;

await act(async () => {
Expand All @@ -290,7 +290,7 @@ describe('routes/Settings.tsx', () => {
fireEvent.click(getByLabelText('Light'));

expect(updateSetting).toHaveBeenCalledTimes(1);
expect(updateSetting).toHaveBeenCalledWith('appearance', 'LIGHT');
expect(updateSetting).toHaveBeenCalledWith('theme', 'LIGHT');
});

it('should go to the enterprise login route', async () => {
Expand Down
Loading