-
Notifications
You must be signed in to change notification settings - Fork 22
feat(notes): blank note editor + edit flow #1427
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
Open
rtBot
wants to merge
7
commits into
feat/redesign
Choose a base branch
from
claude/feat/notes-editor
base: feat/redesign
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d41d015
feat(notes): add blank note editor with create + edit flows
rtBot ede9c9d
refactor(notes): address PR 1427 review feedback
rtBot 6cb5568
refactor: simplify notes editor
b1ink0 ce53cc6
chore: remove unnecessary routes
b1ink0 e88cf7e
refactor(notes): switch editor to nested dynamic-segment routes
rtBot f05053e
Merge branch 'feat/redesign' into claude/feat/notes-editor
b1ink0 5611569
refactor: move project details tabs to route structure
b1ink0 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
There are no files selected for viewing
82 changes: 55 additions & 27 deletions
82
frontend/packages/app/src/pages/project-details/index.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
26 changes: 26 additions & 0 deletions
26
frontend/packages/app/src/pages/project-details/tabs/constants.ts
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,26 @@ | ||
| import type { ComponentProps } from "react"; | ||
| import { TabList } from "@rtcamp/frappe-ui-react"; | ||
|
|
||
| export const TAB_KEYS = [ | ||
| "overview", | ||
| "calendar", | ||
| "tracking", | ||
| "risks", | ||
| "notes", | ||
| "email", | ||
| "to-do", | ||
| "feedback", | ||
| ] as const; | ||
|
|
||
| export type TabKey = (typeof TAB_KEYS)[number]; | ||
|
|
||
| export const TAB_NAV: ComponentProps<typeof TabList>["tabs"] = [ | ||
| { label: "Overview", content: null }, | ||
| { label: "Calendar", content: null }, | ||
| { label: "Tracking", content: null }, | ||
| { label: "Risks", content: null }, | ||
| { label: "Notes", content: null }, | ||
| { label: "Email", content: null }, | ||
| { label: "To-do", content: null }, | ||
| { label: "Feedback", content: null }, | ||
| ]; |
35 changes: 0 additions & 35 deletions
35
frontend/packages/app/src/pages/project-details/tabs/index.tsx
This file was deleted.
Oops, something went wrong.
198 changes: 198 additions & 0 deletions
198
frontend/packages/app/src/pages/project-details/tabs/notes/editor/index.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,198 @@ | ||
| /** | ||
| * External dependencies. | ||
| */ | ||
| import { useEffect, useState } from "react"; | ||
| import { useNavigate, useParams } from "react-router-dom"; | ||
| import { Spinner } from "@next-pms/design-system/components"; | ||
| import { | ||
| Avatar, | ||
| Button, | ||
| ErrorMessage, | ||
| TextEditor, | ||
| useToasts, | ||
| } from "@rtcamp/frappe-ui-react"; | ||
| import { useForm } from "@tanstack/react-form"; | ||
| import { | ||
| FrappeError, | ||
| useFrappeGetCall, | ||
| useFrappePostCall, | ||
| } from "frappe-react-sdk"; | ||
|
|
||
| /** | ||
| * Internal dependencies. | ||
| */ | ||
| import { ROUTES } from "@/lib/constant"; | ||
| import { parseFrappeErrorMsg } from "@/lib/utils"; | ||
| import { useProjectDetail } from "@/pages/project-details/context"; | ||
| import { useUser } from "@/providers/user"; | ||
| import { noteFormSchema } from "./schema"; | ||
| import { useNotes } from "../context"; | ||
|
|
||
| export function NoteEditor() { | ||
| const navigate = useNavigate(); | ||
| const { projectId: routeProjectId = "", noteId } = useParams<{ | ||
| projectId: string; | ||
| noteId?: string; | ||
| }>(); | ||
| const mode: "edit" | "new" = noteId ? "edit" : "new"; | ||
| const userName = useUser((s) => s.state.userName); | ||
| const userImage = useUser((s) => s.state.image); | ||
| const projectId = useProjectDetail((s) => s.projectId); | ||
| const refresh = useNotes((s) => s.actions.refresh); | ||
| const toast = useToasts(); | ||
| const [isFormInitialized, setIsFormInitialized] = useState(false); | ||
|
|
||
| const { call: createNote, loading: isCreating } = useFrappePostCall( | ||
| "next_pms.timesheet.api.project_status_update.create_project_status_update", | ||
| ); | ||
| const { call: updateNote, loading: isUpdating } = useFrappePostCall( | ||
| "next_pms.timesheet.api.project_status_update.update_project_status_update", | ||
| ); | ||
| const { data: noteData, isLoading: isNoteLoading } = useFrappeGetCall( | ||
| "next_pms.timesheet.api.project_status_update.get_project_status_update", | ||
| { name: noteId }, | ||
| mode === "edit" && noteId ? undefined : null, | ||
| ); | ||
|
|
||
| const form = useForm({ | ||
| defaultValues: { | ||
| project: projectId, | ||
| title: "", | ||
| description: "", | ||
| status: "Publish", | ||
| }, | ||
| validators: { | ||
| onSubmit: noteFormSchema, | ||
| }, | ||
| onSubmit: async ({ value }) => { | ||
| try { | ||
| const payload = { | ||
| title: value.title, | ||
| description: value.description, | ||
| status: value.status, | ||
| }; | ||
|
|
||
| if (mode === "new") { | ||
| await createNote({ | ||
| project: value.project, | ||
| ...payload, | ||
| }); | ||
| } else { | ||
| await updateNote({ | ||
| name: noteId, | ||
| ...payload, | ||
| }); | ||
| } | ||
|
|
||
| toast.success("Note saved"); | ||
| await refresh(); | ||
| navigate(`${ROUTES.project}/${routeProjectId}/notes`); | ||
| } catch (err) { | ||
| const error = parseFrappeErrorMsg(err as FrappeError); | ||
| toast.error(error); | ||
| } | ||
| }, | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| if (mode === "edit" && noteData?.message) { | ||
| form.setFieldValue("title", noteData.message.title); | ||
| form.setFieldValue("description", noteData.message.description); | ||
| setIsFormInitialized(true); | ||
| } else if (mode === "new") { | ||
| form.reset({ | ||
| project: projectId, | ||
| title: "", | ||
| description: "", | ||
| status: "Publish", | ||
| }); | ||
| setIsFormInitialized(true); | ||
| } | ||
| }, [noteData, mode, form, projectId]); | ||
|
|
||
| const isInputDisabled = isCreating || isUpdating || isNoteLoading; | ||
|
|
||
| return ( | ||
| <div className="flex justify-center"> | ||
| {isNoteLoading || !isFormInitialized ? ( | ||
| <Spinner className="py-10" /> | ||
| ) : ( | ||
| <div className="max-w-200 w-full p-4"> | ||
| <div className="flex items-center justify-between gap-8"> | ||
| <div className="flex items-center gap-2"> | ||
| <Avatar | ||
| size="xs" | ||
| shape="circle" | ||
| label={userName} | ||
| image={userImage || undefined} | ||
| /> | ||
| <span className="truncate text-base font-medium text-ink-gray-7"> | ||
| {userName} | ||
| </span> | ||
| </div> | ||
| <form.Subscribe selector={(state) => state.isDirty}> | ||
| {(isDirty) => ( | ||
| <Button | ||
| variant="solid" | ||
| theme="gray" | ||
| size="sm" | ||
| label="Save note" | ||
| loading={isCreating || isUpdating} | ||
| disabled={isInputDisabled || !isDirty} | ||
| onClick={() => form.handleSubmit()} | ||
| /> | ||
| )} | ||
| </form.Subscribe> | ||
| </div> | ||
| <div className="flex flex-col gap-2 pt-4"> | ||
| <form.Field | ||
| name="title" | ||
| children={(field) => { | ||
| return ( | ||
| <> | ||
| <input | ||
| value={field.state.value} | ||
| onChange={(e) => field.handleChange(e.target.value)} | ||
| disabled={isInputDisabled} | ||
| placeholder="Add note title" | ||
| aria-label="Note title" | ||
| className="w-full resize-none border-0 bg-transparent text-3xl font-semibold leading-tight text-ink-gray-8 placeholder:text-ink-gray-4 focus:outline-none" | ||
| /> | ||
| {!field.state.meta.isValid && ( | ||
| <ErrorMessage | ||
| message={field.state.meta.errors[0]?.message} | ||
| /> | ||
| )} | ||
| </> | ||
| ); | ||
| }} | ||
| /> | ||
|
|
||
| <form.Field | ||
| name="description" | ||
| children={(field) => { | ||
| return ( | ||
| <> | ||
| <TextEditor | ||
| content={field.state.value} | ||
| onChange={(value) => field.handleChange(value)} | ||
| placeholder="Type a note description..." | ||
| editable={!isInputDisabled} | ||
| fixedMenu={false} | ||
| editorClass="prose prose-sm max-w-none min-h-[400px] text-ink-gray-8 focus:outline-none" | ||
| /> | ||
| {!field.state.meta.isValid && ( | ||
| <ErrorMessage | ||
| message={field.state.meta.errors[0]?.message} | ||
| /> | ||
| )} | ||
| </> | ||
| ); | ||
| }} | ||
| /> | ||
| </div> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
20 changes: 20 additions & 0 deletions
20
frontend/packages/app/src/pages/project-details/tabs/notes/editor/schema.ts
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,20 @@ | ||
| import { z } from "zod"; | ||
| import { NOTE_STATUS } from "../types"; | ||
|
|
||
| export const noteFormSchema = z.object({ | ||
| project: z | ||
| .string({ required_error: "Project Id is required" }) | ||
| .trim() | ||
| .min(1, { message: "Project Id is required" }), | ||
| title: z | ||
| .string({ required_error: "Title is required" }) | ||
| .trim() | ||
| .min(1, { message: "Title is required" }), | ||
| description: z | ||
| .string({ required_error: "Description is required" }) | ||
| .trim() | ||
| .min(1, { message: "Description is required" }), | ||
| status: z.enum(NOTE_STATUS, { required_error: "Status is required" }), | ||
| }); | ||
|
|
||
| export type NoteFormValues = z.infer<typeof noteFormSchema>; |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sidebar is not visible for this page. Update about/index to look at current location for rendering
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in e88cf7e — editor%2Findex.tsx (sidebar self-hides via useMatch in about/index.tsx).