-
Notifications
You must be signed in to change notification settings - Fork 899
feat: add user quiet hours settings page #9525
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
37e26da
feat: add user quiet hours settings page
deansheather a4faf5b
fixup! feat: add user quiet hours settings page
deansheather 36f0b5d
fixup! feat: add user quiet hours settings page
deansheather fbaaff8
fixup! feat: add user quiet hours settings page
deansheather 6b188cd
fixup! feat: add user quiet hours settings page
deansheather 4d65381
fixup! feat: add user quiet hours settings page
deansheather File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
feat: add user quiet hours settings page
- Loading branch information
commit 37e26da070d163b87ab3e3d77e3500bdd50d733d
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
site/src/pages/UserSettingsPage/SchedulePage/SchedulePage.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { fireEvent, screen, waitFor } from "@testing-library/react" | ||
import * as API from "../../../api/api" | ||
import * as AccountForm from "../../../components/SettingsAccountForm/SettingsAccountForm" | ||
import { renderWithAuth } from "../../../testHelpers/renderHelpers" | ||
import * as AuthXService from "../../../xServices/auth/authXService" | ||
import { SchedulePage } from "./SchedulePage" | ||
import i18next from "i18next" | ||
import { mockApiError } from "testHelpers/entities" | ||
|
||
const { t } = i18next | ||
|
||
const renderPage = () => { | ||
return renderWithAuth(<SchedulePage />) | ||
} | ||
|
||
const newData = { | ||
username: "user", | ||
} | ||
|
||
const fillAndSubmitForm = async () => { | ||
await waitFor(() => screen.findByLabelText("Username")) | ||
fireEvent.change(screen.getByLabelText("Username"), { | ||
target: { value: newData.username }, | ||
}) | ||
fireEvent.click(screen.getByText(AccountForm.Language.updateSettings)) | ||
} | ||
|
||
describe("SchedulePage", () => { | ||
describe("when it is a success", () => { | ||
it("shows the success message", async () => { | ||
jest.spyOn(API, "updateProfile").mockImplementationOnce((userId, data) => | ||
Promise.resolve({ | ||
id: userId, | ||
email: "user@coder.com", | ||
created_at: new Date().toString(), | ||
status: "active", | ||
organization_ids: ["123"], | ||
roles: [], | ||
avatar_url: "", | ||
last_seen_at: new Date().toString(), | ||
login_type: "password", | ||
...data, | ||
}), | ||
) | ||
const { user } = renderPage() | ||
await fillAndSubmitForm() | ||
|
||
const successMessage = await screen.findByText( | ||
AuthXService.Language.successProfileUpdate, | ||
) | ||
expect(successMessage).toBeDefined() | ||
expect(API.updateProfile).toBeCalledTimes(1) | ||
expect(API.updateProfile).toBeCalledWith(user.id, newData) | ||
}) | ||
}) | ||
|
||
describe("when the username is already taken", () => { | ||
it("shows an error", async () => { | ||
jest.spyOn(API, "updateProfile").mockRejectedValueOnce( | ||
mockApiError({ | ||
message: "Invalid profile", | ||
validations: [ | ||
{ detail: "Username is already in use", field: "username" }, | ||
], | ||
}), | ||
) | ||
|
||
const { user } = renderPage() | ||
await fillAndSubmitForm() | ||
|
||
const errorMessage = await screen.findByText("Username is already in use") | ||
expect(errorMessage).toBeDefined() | ||
expect(API.updateProfile).toBeCalledTimes(1) | ||
expect(API.updateProfile).toBeCalledWith(user.id, newData) | ||
}) | ||
}) | ||
|
||
describe("when it is an unknown error", () => { | ||
it("shows a generic error message", async () => { | ||
jest.spyOn(API, "updateProfile").mockRejectedValueOnce({ | ||
data: "unknown error", | ||
}) | ||
|
||
const { user } = renderPage() | ||
await fillAndSubmitForm() | ||
|
||
const errorText = t("warningsAndErrors.somethingWentWrong", { | ||
ns: "common", | ||
}) | ||
const errorMessage = await screen.findByText(errorText) | ||
expect(errorMessage).toBeDefined() | ||
expect(API.updateProfile).toBeCalledTimes(1) | ||
expect(API.updateProfile).toBeCalledWith(user.id, newData) | ||
}) | ||
}) | ||
}) |
59 changes: 59 additions & 0 deletions
59
site/src/pages/UserSettingsPage/SchedulePage/SchedulePage.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { FC, useEffect, useState } from "react" | ||
import { Section } from "../../../components/SettingsLayout/Section" | ||
import { AccountForm } from "../../../components/SettingsAccountForm/SettingsAccountForm" | ||
import { useAuth } from "components/AuthProvider/AuthProvider" | ||
import { useMe } from "hooks/useMe" | ||
import { usePermissions } from "hooks/usePermissions" | ||
import { UserQuietHoursScheduleResponse } from "api/typesGenerated" | ||
import * as API from "api/api" | ||
|
||
export const SchedulePage: FC = () => { | ||
const [authState, authSend] = useAuth() | ||
const me = useMe() | ||
const permissions = usePermissions() | ||
const { updateProfileError } = authState.context | ||
const canEditUsers = permissions && permissions.updateUsers | ||
|
||
const [quietHoursSchedule, setQuietHoursSchedule] = useState<UserQuietHoursScheduleResponse | undefined>(undefined) | ||
const [quietHoursScheduleError, setQuietHoursScheduleError] = useState<string>("") | ||
|
||
useEffect(() => { | ||
setQuietHoursSchedule(undefined) | ||
API.getUserQuietHoursSchedule(me.id) | ||
.then(response => { | ||
setQuietHoursSchedule(response) | ||
setQuietHoursScheduleError("") | ||
}) | ||
.catch(error => { | ||
setQuietHoursSchedule(undefined) | ||
setQuietHoursScheduleError(error.message) | ||
}) | ||
}, [me.id]) | ||
|
||
return ( | ||
<Section title="Schedule" description="Manage your quiet hours schedule"> | ||
<pre> | ||
{JSON.stringify(quietHoursSchedule, null, 2)} | ||
|
||
{quietHoursScheduleError} | ||
</pre> | ||
<AccountForm | ||
editable={Boolean(canEditUsers)} | ||
email={me.email} | ||
updateProfileError={updateProfileError} | ||
isLoading={authState.matches("signedIn.profile.updatingProfile")} | ||
initialValues={{ | ||
username: me.username, | ||
}} | ||
onSubmit={(data) => { | ||
authSend({ | ||
type: "UPDATE_PROFILE", | ||
data, | ||
}) | ||
}} | ||
/> | ||
</Section> | ||
) | ||
} | ||
|
||
export default SchedulePage |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.