-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve order events history (#5371)
* Use orderNoteAdd mutation instead of orderAddNote * Show when note is updated with reloaded and note id * Add handling note update * Add loading state handling * Extract messages * Fix imports and tests * Add tests * Add changeset * Fix typing * Improve typing * Add subtitle with docs link * Extract messages
- Loading branch information
Showing
21 changed files
with
557 additions
and
126 deletions.
There are no files selected for viewing
This file contains 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,5 @@ | ||
--- | ||
"saleor-dashboard": patch | ||
--- | ||
|
||
You can now edit note in order details. Notes in order details now show id of note, id of related note and type of note "added" or "updated" |
This file contains 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 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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { OrderEventFragment } from "@dashboard/graphql/types.generated"; | ||
import Wrapper from "@test/wrapper"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { act, render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import React from "react"; | ||
|
||
import TimelineNote from "./TimelineNote"; | ||
|
@@ -142,4 +143,85 @@ describe("TimelineNote", () => { | |
expect(initials).toBeNull(); | ||
expect(avatar).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders note id and refer id", () => { | ||
// Arrange | ||
const noteId = "T3JkZXJFdmVudDozNDM3"; | ||
const noteRelatedId = "T3JkZXJFdmVudDozNDQx"; | ||
const mockedUser = { | ||
avatar: null, | ||
id: "1", | ||
email: "[email protected]", | ||
firstName: "Test", | ||
lastName: "User", | ||
__typename: "User", | ||
} satisfies OrderEventFragment["user"]; | ||
|
||
// Act | ||
render( | ||
<TimelineNote | ||
app={null} | ||
user={mockedUser} | ||
date={wrapperFriendlyDate} | ||
message="Note" | ||
hasPlainDate={false} | ||
id={noteId} | ||
relatedId={noteRelatedId} | ||
/>, | ||
{ wrapper: Wrapper }, | ||
); | ||
|
||
// Assert | ||
expect(screen.getByText("Test User")).toBeInTheDocument(); | ||
expect(screen.getByText("Note")).toBeInTheDocument(); | ||
expect(screen.getByText("TU")).toBeInTheDocument(); | ||
expect(screen.getByText("a few seconds ago")).toBeInTheDocument(); | ||
expect(screen.getByText(`Note id: ${noteId}`)).toBeInTheDocument(); | ||
expect(screen.getByText(new RegExp(noteRelatedId))).toBeInTheDocument(); | ||
}); | ||
|
||
it("should edit note", async () => { | ||
// Arrange | ||
const noteId = "T3JkZXJFdmVudDozNDM3"; | ||
const noteRelatedId = "T3JkZXJFdmVudDozNDQx"; | ||
const onNoteUpdate = jest.fn(); | ||
const onNoteUpdateLoading = false; | ||
const mockedUser = { | ||
avatar: null, | ||
id: "1", | ||
email: "[email protected]", | ||
firstName: "Test", | ||
lastName: "User", | ||
__typename: "User", | ||
} satisfies OrderEventFragment["user"]; | ||
|
||
render( | ||
<TimelineNote | ||
app={null} | ||
user={mockedUser} | ||
date={wrapperFriendlyDate} | ||
message="Note" | ||
hasPlainDate={false} | ||
id={noteId} | ||
relatedId={noteRelatedId} | ||
onNoteUpdate={onNoteUpdate} | ||
onNoteUpdateLoading={onNoteUpdateLoading} | ||
/>, | ||
{ wrapper: Wrapper }, | ||
); | ||
|
||
// Act | ||
await act(async () => { | ||
await userEvent.click(screen.getByTestId("edit-note")); | ||
}); | ||
|
||
await act(async () => { | ||
await userEvent.clear(screen.getByRole("textbox")); | ||
await userEvent.type(screen.getByRole("textbox"), "New note"); | ||
await userEvent.click(screen.getByRole("button", { name: /save/i })); | ||
}); | ||
|
||
// Assert | ||
expect(onNoteUpdate).toHaveBeenCalledWith(noteId, "New note"); | ||
}); | ||
}); |
This file contains 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 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,58 @@ | ||
import { ConfirmButton } from "@dashboard/components/ConfirmButton"; | ||
import { buttonMessages } from "@dashboard/intl"; | ||
import { Box, Button, Textarea } from "@saleor/macaw-ui-next"; | ||
import React from "react"; | ||
import { useForm } from "react-hook-form"; | ||
import { FormattedMessage } from "react-intl"; | ||
|
||
interface TimelineNoteEditProps { | ||
id: string; | ||
note: string; | ||
loading: boolean; | ||
onSubmit: (id: string, message: string) => Promise<unknown>; | ||
onCancel: () => void; | ||
} | ||
|
||
interface TimelineNoteEditData { | ||
note: string; | ||
} | ||
|
||
export const TimelineNoteEdit = ({ | ||
onCancel, | ||
note, | ||
onSubmit, | ||
id, | ||
loading, | ||
}: TimelineNoteEditProps) => { | ||
const { handleSubmit, register } = useForm<TimelineNoteEditData>({ | ||
defaultValues: { | ||
note, | ||
}, | ||
}); | ||
|
||
const submitHandler = async (data: TimelineNoteEditData) => { | ||
await onSubmit(id, data.note); | ||
onCancel(); | ||
}; | ||
|
||
return ( | ||
<Box as="form" marginBottom={6} width="100%" onSubmit={handleSubmit(submitHandler)}> | ||
<Textarea autoFocus fontSize={4} paddingY={2.5} paddingX={4} rows={5} {...register("note")} /> | ||
<Box marginTop={3} display="flex" alignItems="center" justifyContent="flex-end" gap={2}> | ||
<Button disabled={loading} variant="secondary" onClick={onCancel}> | ||
<FormattedMessage {...buttonMessages.cancel} /> | ||
</Button> | ||
<ConfirmButton | ||
data-test-id="save-note" | ||
disabled={loading} | ||
transitionState={loading ? "loading" : "default"} | ||
variant="primary" | ||
type="button" | ||
onClick={handleSubmit(submitHandler)} | ||
> | ||
<FormattedMessage {...buttonMessages.save} /> | ||
</ConfirmButton> | ||
</Box> | ||
</Box> | ||
); | ||
}; |
Oops, something went wrong.