From 86493481203d1b218c80ec95b1fa2a3b6c3606c5 Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Thu, 20 Aug 2026 15:08:26 +0300 Subject: [PATCH] Always show practice story fields on step 1 and add rich text editors. Remove lesson-only field hiding from ContextStep and use TipTap for story description and quick tips in create/edit practice flows. Co-authored-by: Cursor --- package-lock.json | 649 +++++++++++++++++- package.json | 3 + src/components/ui/rich-text-content.tsx | 33 + src/components/ui/rich-text-editor.tsx | 185 +++++ src/index.css | 8 + src/lib/richText.ts | 18 + .../content-management/AddPracticeFlow.tsx | 3 +- .../content-management/EditPracticeFlow.tsx | 3 +- .../components/practice-steps/ContextStep.tsx | 170 +++-- .../PracticeSequentialReview.tsx | 12 +- .../components/practice-steps/ReviewStep.tsx | 2 - .../practice-steps/ScenarioStep.tsx | 42 +- 12 files changed, 999 insertions(+), 129 deletions(-) create mode 100644 src/components/ui/rich-text-content.tsx create mode 100644 src/components/ui/rich-text-editor.tsx create mode 100644 src/lib/richText.ts diff --git a/package-lock.json b/package-lock.json index 8bab665..494d7e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,9 @@ "@radix-ui/react-dropdown-menu": "^2.1.16", "@radix-ui/react-separator": "^1.1.8", "@radix-ui/react-slot": "^1.2.4", + "@tiptap/extension-placeholder": "^3.30.2", + "@tiptap/react": "^3.30.2", + "@tiptap/starter-kit": "^3.30.2", "axios": "^1.13.2", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", @@ -94,6 +97,7 @@ "integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "^7.27.1", "@babel/generator": "^7.28.5", @@ -362,6 +366,7 @@ "resolved": "https://registry.npmjs.org/@dnd-kit/core/-/core-6.3.1.tgz", "integrity": "sha512-xkGBRQQab4RLwgXxoqETICr6S5JlogafbhNsidmrkVv2YRs5MLwpjoF2qpiGjQt8S9AoxtIV603s0GIUpY5eYQ==", "license": "MIT", + "peer": true, "dependencies": { "@dnd-kit/accessibility": "^3.1.1", "@dnd-kit/utilities": "^3.2.2", @@ -1011,6 +1016,7 @@ "resolved": "https://registry.npmjs.org/@floating-ui/dom/-/dom-1.7.4.tgz", "integrity": "sha512-OOchDgh4F2CchOX94cRVqhvy7b3AFb+/rQXyswmzmGakRfkMgoWVjfnLWkRirfLEfuD4ysVW16eXzwt3jHIzKA==", "license": "MIT", + "peer": true, "dependencies": { "@floating-ui/core": "^1.7.3", "@floating-ui/utils": "^0.2.10" @@ -2690,6 +2696,453 @@ "integrity": "sha512-e7Mew686owMaPJVNNLs55PUvgz371nKgwsc4vxE49zsODpJEnxgxRo2y/OKrqueavXgZNMDVj3DdHFlaSAeU8g==", "license": "MIT" }, + "node_modules/@tiptap/core": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/core/-/core-3.30.2.tgz", + "integrity": "sha512-QbZC/s1OOqcoUdkhIY16TjR/gCtR0qAk9e4bJwUqOJqZuv5ozqCL5hzWm22jjTPp6c6Ei2tPd6t30VwfIKW4lQ==", + "license": "MIT", + "peer": true, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/pm": "3.30.2" + } + }, + "node_modules/@tiptap/extension-blockquote": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-blockquote/-/extension-blockquote-3.30.2.tgz", + "integrity": "sha512-BOkwhZenek7vzXBOgKppSrlx4YryBdAYu1p1MXKn0R9A9eNmE2HVhmm0gG49+E8BhsE/TG8wKVclwET42JJiIg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2", + "@tiptap/pm": "3.30.2" + } + }, + "node_modules/@tiptap/extension-bold": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-bold/-/extension-bold-3.30.2.tgz", + "integrity": "sha512-MsvJhPgYejY2D9MhwYJv8AmscozvLBI8qtJ7YLdYZBWkMR4bgmxHq5+xqEfBsao9bOMMwBon9p3+P+/Tq5ReWA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2" + } + }, + "node_modules/@tiptap/extension-bubble-menu": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-bubble-menu/-/extension-bubble-menu-3.30.2.tgz", + "integrity": "sha512-oS0WiWNXHKpiPYMkcnHm1j7iEvufTGGtLFtcJJd3olb5OS6V2acoXVDL0nNJDmRQ32K3QXut3fbRcMseMxT+lw==", + "license": "MIT", + "optional": true, + "dependencies": { + "@floating-ui/dom": "^1.0.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2", + "@tiptap/pm": "3.30.2" + } + }, + "node_modules/@tiptap/extension-bullet-list": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-bullet-list/-/extension-bullet-list-3.30.2.tgz", + "integrity": "sha512-+awIL/TUz4aB3rL68igU1rWfaaoBIAkPcakkktkRq8gYf0bd9eSb48P6kHkpx/3q+JyK7g9vsnltLNHNh6twnA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-list": "3.30.2" + } + }, + "node_modules/@tiptap/extension-code": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-code/-/extension-code-3.30.2.tgz", + "integrity": "sha512-r8EZk3R9yGpF6v5xxafAU1HwrD/e+RpbfnmVi2TeB/ZHAsVO62fW96E32G0t6IdaCtOFtAd85hkDAaOfCT4yGg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2" + } + }, + "node_modules/@tiptap/extension-code-block": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-code-block/-/extension-code-block-3.30.2.tgz", + "integrity": "sha512-9otGKaQZmePHrLXFtCtz+BYDn5z4sSumTkUqQIQHz0gVxwPoTi7g51RedwxvViTb/zu2XV5ROXYLHIxKxypMPg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2", + "@tiptap/pm": "3.30.2" + } + }, + "node_modules/@tiptap/extension-document": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-document/-/extension-document-3.30.2.tgz", + "integrity": "sha512-+xIv67V+/2L1uvz98FAT5W7kWEfHwfNV3MD7b4UsKPU0lhcCWuVOXy0JB8yYmdNExqpI7xT9g3MWzREoBvBQSg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2" + } + }, + "node_modules/@tiptap/extension-dropcursor": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-dropcursor/-/extension-dropcursor-3.30.2.tgz", + "integrity": "sha512-nyRKUmItATnKI9AiRChmjhcBbCEsNxRu+AaCz+cx8EvnAcNHsVRdNYL5PmBs3WlNA/Et4Eb2DG0hVQDnNF61eg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extensions": "3.30.2" + } + }, + "node_modules/@tiptap/extension-floating-menu": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-floating-menu/-/extension-floating-menu-3.30.2.tgz", + "integrity": "sha512-A8PLvvh8W6PUMrqh+EpBerxm+Ucr0irGxJvwAnzYQmNGNIJ9U4OVgw4OcEU+9JH0gMmEzDcHzMPP2s/s1lIcyw==", + "license": "MIT", + "optional": true, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@floating-ui/dom": "^1.0.0", + "@tiptap/core": "3.30.2", + "@tiptap/pm": "3.30.2" + } + }, + "node_modules/@tiptap/extension-gapcursor": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-gapcursor/-/extension-gapcursor-3.30.2.tgz", + "integrity": "sha512-7Xk0ut6FM+RAsvKxDN3bAtk7zvYZ6Aa8pawJ6s7dLAmLR9JwrZevlcL4FSrj4bR7rqKOj92RYCFxzgTEbWimag==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extensions": "3.30.2" + } + }, + "node_modules/@tiptap/extension-hard-break": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-hard-break/-/extension-hard-break-3.30.2.tgz", + "integrity": "sha512-IxSNgmG3d4OZdUTeebrOI7SxdIWXXJqlcGiSNDabWqxipUitfy3mZ3gDDE6G01koKxZRbhz4KIplAZlpxnTFSg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2" + } + }, + "node_modules/@tiptap/extension-heading": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-heading/-/extension-heading-3.30.2.tgz", + "integrity": "sha512-PblDvgSJ05p1t6hzyPi02xeiBjB0M2abReoGEImqSWCy79UqnAGacgsZo4EeEawtJV1NEP8chhvmX+nRtzdT1A==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2" + } + }, + "node_modules/@tiptap/extension-horizontal-rule": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-horizontal-rule/-/extension-horizontal-rule-3.30.2.tgz", + "integrity": "sha512-j8aswLTsuEdJKC62DF+kw0EgvIRL7QMUyAVp2fdjR0qgM0ZVlEwCC4qIEq3kK9tFVU4kRtQ5BSj/jn6QwrlbCA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2", + "@tiptap/pm": "3.30.2" + } + }, + "node_modules/@tiptap/extension-italic": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-italic/-/extension-italic-3.30.2.tgz", + "integrity": "sha512-pp8uaiuXsUbLm5rYzR1jlWbwm1mAahRajdHwAKBtthFRB2rDvC7ZWhKaCSoKhZvfIDRmu9/B67+uAHoutL0dCA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2" + } + }, + "node_modules/@tiptap/extension-link": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-link/-/extension-link-3.30.2.tgz", + "integrity": "sha512-jwdcymKcrbFpj5hRAuGVLCq8FieVkGFnENyroYmvkad+XAt8ZLy/MTFYRN6SK3ukH6PZMY7H4iObGtciQaC5nw==", + "license": "MIT", + "dependencies": { + "linkifyjs": "^4.3.3" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2", + "@tiptap/pm": "3.30.2" + } + }, + "node_modules/@tiptap/extension-list": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-list/-/extension-list-3.30.2.tgz", + "integrity": "sha512-MIUpo1Bd9Rf1Qg+TNYNwDZ4xsfFeQahjU9Xhy6UcaszKQzbAM7KCzn5BObNytK1NdcqNHsC8Wj5vFvMKEzrXdw==", + "license": "MIT", + "peer": true, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2", + "@tiptap/pm": "3.30.2" + } + }, + "node_modules/@tiptap/extension-list-item": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-list-item/-/extension-list-item-3.30.2.tgz", + "integrity": "sha512-HWgRCRlGxulE+hN1VUcnWD6P2NE08VBgGtcaxOfdXVqaI93BCK6AhRQZGpLsfKgajLk+5DXTBraaitwnBqzCxg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-list": "3.30.2" + } + }, + "node_modules/@tiptap/extension-list-keymap": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-list-keymap/-/extension-list-keymap-3.30.2.tgz", + "integrity": "sha512-TTve3WOlQaYu1ahMqsQ/T0wzaxfgZvcOl3/OuPyInOi8QtxXhqGhFjmYe5jOr56G9W2QDuFWVsZecVwfDte9zg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-list": "3.30.2" + } + }, + "node_modules/@tiptap/extension-ordered-list": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-ordered-list/-/extension-ordered-list-3.30.2.tgz", + "integrity": "sha512-Z7OO1HcF0idda1n6vodXeQ3h2ylN9JR4IfIGUYkar5Xl9JusK8PDETTBQZQn//96p49I2d+GoWsD2LXPtjHXXg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extension-list": "3.30.2" + } + }, + "node_modules/@tiptap/extension-paragraph": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-paragraph/-/extension-paragraph-3.30.2.tgz", + "integrity": "sha512-ulEu3LNt+kPVAWEnrhoz13Fs8Q/v/8NUxQbAeteuBchQ8joxJXuWExhpy1fUfZir5+b+W5z7/NesgPjZQfv47w==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2" + } + }, + "node_modules/@tiptap/extension-placeholder": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-placeholder/-/extension-placeholder-3.30.2.tgz", + "integrity": "sha512-Bj1seUvPCoRrD/LpzMoKD+jQIjxuc+oq931GpPq4wobSUUbD4pF/0NMwpCLpiHO19QnTQz8+9p2dqPdlc44LHA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/extensions": "3.30.2" + } + }, + "node_modules/@tiptap/extension-strike": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-strike/-/extension-strike-3.30.2.tgz", + "integrity": "sha512-fBLxMXz6hYIURzLOD+/L6aVATztsKham00ANWmGi13vN0hx2lQMYZffN+gR+QqiCDfMQxBXzrf5a7tJuDiQHLQ==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2" + } + }, + "node_modules/@tiptap/extension-text": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-text/-/extension-text-3.30.2.tgz", + "integrity": "sha512-n/iZnirgRmXet6f97kolAnP3j8DsgLSiTbz/KLWc8eBYiFmkjRzkuisOm5xuGdfGIxwpB4x3tlSF4ef4DLnbRg==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2" + } + }, + "node_modules/@tiptap/extension-underline": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extension-underline/-/extension-underline-3.30.2.tgz", + "integrity": "sha512-SZiTMnvqXcnrtJX+X25ZbYsuDO83haGOVMBD/O+mAWYNYXhaSc5Rkph5czzItxrd+Yyp/vs4PiwD7XTNbfqmpA==", + "license": "MIT", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2" + } + }, + "node_modules/@tiptap/extensions": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/extensions/-/extensions-3.30.2.tgz", + "integrity": "sha512-2LqAHXk26QDsryW+beECxYeBzv5Ylk4GuB3cOmfghS7/G37R2W+Te3TkUK7BT0EWoDryvBT57/5q0DEFIhfZZg==", + "license": "MIT", + "peer": true, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2", + "@tiptap/pm": "3.30.2" + } + }, + "node_modules/@tiptap/pm": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/pm/-/pm-3.30.2.tgz", + "integrity": "sha512-BJN8tUx4ppFN3R3cV/FJfrJbJkvo1lj4uciq+nwpjwzdRvFzqIuglWf+HLcJ6CwlYpLOHp7ArgkBg4Q5e60Gog==", + "license": "MIT", + "peer": true, + "dependencies": { + "prosemirror-changeset": "^2.4.1", + "prosemirror-commands": "^1.7.1", + "prosemirror-dropcursor": "^1.8.2", + "prosemirror-gapcursor": "^1.4.1", + "prosemirror-history": "^1.5.0", + "prosemirror-inputrules": "^1.5.1", + "prosemirror-keymap": "^1.2.3", + "prosemirror-model": "^1.25.11", + "prosemirror-schema-list": "^1.5.1", + "prosemirror-state": "^1.4.4", + "prosemirror-tables": "^1.8.5", + "prosemirror-transform": "^1.12.0", + "prosemirror-view": "^1.41.9" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + } + }, + "node_modules/@tiptap/react": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/react/-/react-3.30.2.tgz", + "integrity": "sha512-7hGaTstpUeTmQ008mCPkjz+GSlChWhucgy+PeX0z93v4+nh7qM5F+0lh+kJ9zo6Os5abO7v36GtgHRZdQI6+FQ==", + "license": "MIT", + "dependencies": { + "@types/use-sync-external-store": "^0.0.6", + "fast-equals": "^5.3.3", + "use-sync-external-store": "^1.4.0" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + }, + "optionalDependencies": { + "@tiptap/extension-bubble-menu": "^3.30.2", + "@tiptap/extension-floating-menu": "^3.30.2" + }, + "peerDependencies": { + "@tiptap/core": "3.30.2", + "@tiptap/pm": "3.30.2", + "@types/react": "^17.0.0 || ^18.0.0 || ^19.0.0", + "@types/react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0", + "react": "^17.0.0 || ^18.0.0 || ^19.0.0", + "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0" + } + }, + "node_modules/@tiptap/starter-kit": { + "version": "3.30.2", + "resolved": "https://registry.npmjs.org/@tiptap/starter-kit/-/starter-kit-3.30.2.tgz", + "integrity": "sha512-fJSrhW1CyD4sjYA20evSP4Cp13B/HhbxCdM974K0xpHOVqvCtNU9w2s9hfq9mg2yGoU7MSNHKNYMkJjIi2/Xyw==", + "license": "MIT", + "dependencies": { + "@tiptap/core": "3.30.2", + "@tiptap/extension-blockquote": "3.30.2", + "@tiptap/extension-bold": "3.30.2", + "@tiptap/extension-bullet-list": "3.30.2", + "@tiptap/extension-code": "3.30.2", + "@tiptap/extension-code-block": "3.30.2", + "@tiptap/extension-document": "3.30.2", + "@tiptap/extension-dropcursor": "3.30.2", + "@tiptap/extension-gapcursor": "3.30.2", + "@tiptap/extension-hard-break": "3.30.2", + "@tiptap/extension-heading": "3.30.2", + "@tiptap/extension-horizontal-rule": "3.30.2", + "@tiptap/extension-italic": "3.30.2", + "@tiptap/extension-link": "3.30.2", + "@tiptap/extension-list": "3.30.2", + "@tiptap/extension-list-item": "3.30.2", + "@tiptap/extension-list-keymap": "3.30.2", + "@tiptap/extension-ordered-list": "3.30.2", + "@tiptap/extension-paragraph": "3.30.2", + "@tiptap/extension-strike": "3.30.2", + "@tiptap/extension-text": "3.30.2", + "@tiptap/extension-underline": "3.30.2", + "@tiptap/extensions": "3.30.2", + "@tiptap/pm": "3.30.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/ueberdosis" + } + }, "node_modules/@types/babel__core": { "version": "7.20.5", "resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz", @@ -2818,6 +3271,7 @@ "integrity": "sha512-vnDVpYPMzs4wunl27jHrfmwojOGKya0xyM3sH+UE5iv5uPS6vX7UIoh6m+vQc5LGBq52HBKPIn/zcSZVzeDEZg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "undici-types": "~7.16.0" } @@ -2826,8 +3280,8 @@ "version": "19.2.7", "resolved": "https://registry.npmjs.org/@types/react/-/react-19.2.7.tgz", "integrity": "sha512-MWtvHrGZLFttgeEj28VXHxpmwYbor/ATPYbBfSFZEIRK0ecCFLl2Qo55z52Hss+UV9CRN7trSeq1zbgx7YDWWg==", - "dev": true, "license": "MIT", + "peer": true, "dependencies": { "csstype": "^3.2.2" } @@ -2836,8 +3290,8 @@ "version": "19.2.3", "resolved": "https://registry.npmjs.org/@types/react-dom/-/react-dom-19.2.3.tgz", "integrity": "sha512-jp2L/eY6fn+KgVVQAOqYItbF0VY/YApe5Mz2F0aykSO8gx31bYCZyvSeYxCHKvzHG5eZjc+zyaS5BrBWya2+kQ==", - "dev": true, "license": "MIT", + "peer": true, "peerDependencies": { "@types/react": "^19.2.0" } @@ -2893,6 +3347,7 @@ "integrity": "sha512-6/cmF2piao+f6wSxUsJLZjck7OQsYyRtcOZS02k7XINSNlz93v6emM8WutDQSXnroG2xwYlEVHJI+cPA7CPM3Q==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.50.0", "@typescript-eslint/types": "8.50.0", @@ -3144,6 +3599,7 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -3382,6 +3838,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.9.0", "caniuse-lite": "^1.0.30001759", @@ -3642,7 +4099,6 @@ "version": "3.2.3", "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.2.3.tgz", "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", - "dev": true, "license": "MIT" }, "node_modules/custom-error-instance": { @@ -3979,6 +4435,7 @@ "integrity": "sha512-LEyamqS7W5HB3ujJyvi0HQK/dtVINZvd5mAAp9eT5S/ujByGjiZLCzPcHVzuXbpJDJF/cxwHlfceVUDZ2lnSTw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -4170,6 +4627,15 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-equals": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/fast-equals/-/fast-equals-5.4.1.tgz", + "integrity": "sha512-DjlFSM5Pk9cGcL0q5QXl66eGzx0N6szNgaswwc5ZphlBohjTVJSnGgI+rJVOgOi65qUoQnDZN4nDqi33udtydQ==", + "license": "MIT", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/fast-glob": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.3.tgz", @@ -4816,6 +5282,12 @@ "dev": true, "license": "MIT" }, + "node_modules/linkifyjs": { + "version": "4.3.3", + "resolved": "https://registry.npmjs.org/linkifyjs/-/linkifyjs-4.3.3.tgz", + "integrity": "sha512-P8aEP5U/D1/IlTY2OeYsErdwh9bGuLE30NcXtKEjgdHcahveQoQwM2yZNsioQHsWFz0P7KKudisbrzCgR0sDHg==", + "license": "MIT" + }, "node_modules/locate-path": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-6.0.0.tgz", @@ -5100,6 +5572,12 @@ "node": ">= 0.8.0" } }, + "node_modules/orderedmap": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/orderedmap/-/orderedmap-2.1.1.tgz", + "integrity": "sha512-TvAWxi0nDe1j/rtMcWcIj94+Ffe6n7zhow33h40SKxmsmozs6dz/e+EajymfoFcHd7sxNn8yHM8839uixMOV6g==", + "license": "MIT" + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", @@ -5185,6 +5663,7 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -5238,6 +5717,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "nanoid": "^3.3.11", "picocolors": "^1.1.1", @@ -5395,6 +5875,145 @@ "signal-exit": "^3.0.2" } }, + "node_modules/prosemirror-changeset": { + "version": "2.4.1", + "resolved": "https://registry.npmjs.org/prosemirror-changeset/-/prosemirror-changeset-2.4.1.tgz", + "integrity": "sha512-96WBLhOaYhJ+kPhLg3uW359Tz6I/MfcrQfL4EGv4SrcqKEMC1gmoGrXHecPE8eOwTVCJ4IwgfzM8fFad25wNfw==", + "license": "MIT", + "dependencies": { + "prosemirror-transform": "^1.0.0" + } + }, + "node_modules/prosemirror-commands": { + "version": "1.7.2", + "resolved": "https://registry.npmjs.org/prosemirror-commands/-/prosemirror-commands-1.7.2.tgz", + "integrity": "sha512-q6Q6szxqdu9Xd6EcdKsqXghu5nQdZTpB4Q9yd04WRc7/jt763e/rT60Owh0L1GYY+T46o5rD+9lEN36dZS43tw==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.0.0", + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.10.2" + } + }, + "node_modules/prosemirror-dropcursor": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/prosemirror-dropcursor/-/prosemirror-dropcursor-1.8.3.tgz", + "integrity": "sha512-FoYbsJR8gK+DGlqhNoE29Loa38eIZPzQRIb1VMaDNBoo4OLP6vVof/jR8qFY/6XvUd6Dhug8MDCHl2a/h8RTfQ==", + "license": "MIT", + "dependencies": { + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.1.0", + "prosemirror-view": "^1.1.0" + } + }, + "node_modules/prosemirror-gapcursor": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/prosemirror-gapcursor/-/prosemirror-gapcursor-1.4.1.tgz", + "integrity": "sha512-pMdYaEnjNMSwl11yjEGtgTmLkR08m/Vl+Jj443167p9eB3HVQKhYCc4gmHVDsLPODfZfjr/MmirsdyZziXbQKw==", + "license": "MIT", + "dependencies": { + "prosemirror-keymap": "^1.0.0", + "prosemirror-model": "^1.0.0", + "prosemirror-state": "^1.0.0", + "prosemirror-view": "^1.0.0" + } + }, + "node_modules/prosemirror-history": { + "version": "1.5.0", + "resolved": "https://registry.npmjs.org/prosemirror-history/-/prosemirror-history-1.5.0.tgz", + "integrity": "sha512-zlzTiH01eKA55UAf1MEjtssJeHnGxO0j4K4Dpx+gnmX9n+SHNlDqI2oO1Kv1iPN5B1dm5fsljCfqKF9nFL6HRg==", + "license": "MIT", + "dependencies": { + "prosemirror-state": "^1.2.2", + "prosemirror-transform": "^1.0.0", + "prosemirror-view": "^1.31.0", + "rope-sequence": "^1.3.0" + } + }, + "node_modules/prosemirror-inputrules": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/prosemirror-inputrules/-/prosemirror-inputrules-1.5.1.tgz", + "integrity": "sha512-7wj4uMjKaXWAQ1CDgxNzNtR9AlsuwzHfdFH1ygEHA2KHF2DOEaXl1CJfNPAKCg9qNEh4rum975QLaCiQPyY6Fw==", + "license": "MIT", + "dependencies": { + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.0.0" + } + }, + "node_modules/prosemirror-keymap": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/prosemirror-keymap/-/prosemirror-keymap-1.2.3.tgz", + "integrity": "sha512-4HucRlpiLd1IPQQXNqeo81BGtkY8Ai5smHhKW9jjPKRc2wQIxksg7Hl1tTI2IfT2B/LgX6bfYvXxEpJl7aKYKw==", + "license": "MIT", + "dependencies": { + "prosemirror-state": "^1.0.0", + "w3c-keyname": "^2.2.0" + } + }, + "node_modules/prosemirror-model": { + "version": "1.25.11", + "resolved": "https://registry.npmjs.org/prosemirror-model/-/prosemirror-model-1.25.11.tgz", + "integrity": "sha512-QWg9RhnpLlogAmp3p96uEFrE5txQpFynd4vhBAELkwgOCWQs/X0yCzB3/hrHqiPwf91RG5KyWq6553zs9JqIOQ==", + "license": "MIT", + "dependencies": { + "orderedmap": "^2.0.0" + } + }, + "node_modules/prosemirror-schema-list": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/prosemirror-schema-list/-/prosemirror-schema-list-1.5.1.tgz", + "integrity": "sha512-927lFx/uwyQaGwJxLWCZRkjXG0p48KpMj6ueoYiu4JX05GGuGcgzAy62dfiV8eFZftgyBUvLx76RsMe20fJl+Q==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.0.0", + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.7.3" + } + }, + "node_modules/prosemirror-state": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/prosemirror-state/-/prosemirror-state-1.4.4.tgz", + "integrity": "sha512-6jiYHH2CIGbCfnxdHbXZ12gySFY/fz/ulZE333G6bPqIZ4F+TXo9ifiR86nAHpWnfoNjOb3o5ESi7J8Uz1jXHw==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.0.0", + "prosemirror-transform": "^1.0.0", + "prosemirror-view": "^1.27.0" + } + }, + "node_modules/prosemirror-tables": { + "version": "1.8.5", + "resolved": "https://registry.npmjs.org/prosemirror-tables/-/prosemirror-tables-1.8.5.tgz", + "integrity": "sha512-V/0cDCsHKHe/tfWkeCmthNUcEp1IVO3p6vwN8XtwE9PZQLAZJigbw3QoraAdfJPir4NKJtNvOB8oYGKRl+t0Dw==", + "license": "MIT", + "dependencies": { + "prosemirror-keymap": "^1.2.3", + "prosemirror-model": "^1.25.4", + "prosemirror-state": "^1.4.4", + "prosemirror-transform": "^1.10.5", + "prosemirror-view": "^1.41.4" + } + }, + "node_modules/prosemirror-transform": { + "version": "1.12.0", + "resolved": "https://registry.npmjs.org/prosemirror-transform/-/prosemirror-transform-1.12.0.tgz", + "integrity": "sha512-GxboyN4AMIsoHNtz5uf2r2Ru551i5hWeCMD6E2Ib4Eogqoub0NflniaBPVQ4MrGE5yZ8JV9tUHg9qcZTTrcN4w==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.21.0" + } + }, + "node_modules/prosemirror-view": { + "version": "1.42.2", + "resolved": "https://registry.npmjs.org/prosemirror-view/-/prosemirror-view-1.42.2.tgz", + "integrity": "sha512-Pdg0l5kXm8aLDquFAnQFTCITg0q44sLqBlHlpsVLD9segdOao8TOfQdAhCrCXyVgPSRr6UDDROOIWA3bIrN9YQ==", + "license": "MIT", + "dependencies": { + "prosemirror-model": "^1.25.8", + "prosemirror-state": "^1.0.0", + "prosemirror-transform": "^1.1.0" + } + }, "node_modules/proxy-from-env": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", @@ -5443,6 +6062,7 @@ "resolved": "https://registry.npmjs.org/react/-/react-19.2.3.tgz", "integrity": "sha512-Ku/hhYbVjOQnXDZFv2+RibmLFGwFdeeKHFcOTlrt7xplBnya5OGn/hIRDsqDiSUcfORsDC7MPxwork8jBwsIWA==", "license": "MIT", + "peer": true, "engines": { "node": ">=0.10.0" } @@ -5452,6 +6072,7 @@ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-19.2.3.tgz", "integrity": "sha512-yELu4WmLPw5Mr/lmeEpox5rw3RETacE++JgHqQzd2dg+YbJuat3jH4ingc+WPZhxaoFzdv9y33G+F7Nl5O0GBg==", "license": "MIT", + "peer": true, "dependencies": { "scheduler": "^0.27.0" }, @@ -5463,13 +6084,15 @@ "version": "19.2.5", "resolved": "https://registry.npmjs.org/react-is/-/react-is-19.2.5.tgz", "integrity": "sha512-Dn0t8IQhCmeIT3wu+Apm1/YVsJXsGWi6k4sPdnBIdqMVtHtv0IGi6dcpNpNkNac0zB2uUAqNX3MHzN8c+z2rwQ==", - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/react-redux": { "version": "9.2.0", "resolved": "https://registry.npmjs.org/react-redux/-/react-redux-9.2.0.tgz", "integrity": "sha512-ROY9fvHhwOD9ySfrF0wmvu//bKCQ6AeZZq1nJNtbDC+kk5DuSuNX/n6YWYF/SYy7bSba4D4FSz8DJeKY/S/r+g==", "license": "MIT", + "peer": true, "dependencies": { "@types/use-sync-external-store": "^0.0.6", "use-sync-external-store": "^1.4.0" @@ -5675,7 +6298,8 @@ "version": "5.0.1", "resolved": "https://registry.npmjs.org/redux/-/redux-5.0.1.tgz", "integrity": "sha512-M9/ELqF6fy8FwmkpnF0S3YKOqMyoWJ4+CS5Efg2ct3oY9daQvd/Pc71FpGZsVsbl3Cpb+IIcjBDUnnyBdQbq4w==", - "license": "MIT" + "license": "MIT", + "peer": true }, "node_modules/redux-thunk": { "version": "3.1.0", @@ -5812,6 +6436,12 @@ "fsevents": "~2.3.2" } }, + "node_modules/rope-sequence": { + "version": "1.3.4", + "resolved": "https://registry.npmjs.org/rope-sequence/-/rope-sequence-1.3.4.tgz", + "integrity": "sha512-UT5EDe2cu2E/6O4igUr5PSFs23nvvukicWHx6GnOPlHAiiYbzNuCRQCuiUdHJQcqKalLKlrYJnjY0ySGsXNQXQ==", + "license": "MIT" + }, "node_modules/run-parallel": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/run-parallel/-/run-parallel-1.2.0.tgz", @@ -6158,6 +6788,7 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -6335,6 +6966,7 @@ "integrity": "sha512-dZwN5L1VlUBewiP6H9s2+B3e3Jg96D0vzN+Ry73sOefebhYr9f94wwkMNN/9ouoU8pV1BqA1d1zGk8928cx0rg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.27.0", "fdir": "^6.5.0", @@ -6404,6 +7036,12 @@ } } }, + "node_modules/w3c-keyname": { + "version": "2.2.8", + "resolved": "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.8.tgz", + "integrity": "sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==", + "license": "MIT" + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -6472,6 +7110,7 @@ "integrity": "sha512-0wZ1IRqGGhMP76gLqz8EyfBXKk0J2qo2+H3fi4mcUP/KtTocoX08nmIAHl1Z2kJIZbZee8KOpBCSNPRgauucjw==", "dev": true, "license": "MIT", + "peer": true, "funding": { "url": "https://github.com/sponsors/colinhacks" } diff --git a/package.json b/package.json index e37556c..501931d 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,9 @@ "@radix-ui/react-dropdown-menu": "^2.1.16", "@radix-ui/react-separator": "^1.1.8", "@radix-ui/react-slot": "^1.2.4", + "@tiptap/extension-placeholder": "^3.30.2", + "@tiptap/react": "^3.30.2", + "@tiptap/starter-kit": "^3.30.2", "axios": "^1.13.2", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", diff --git a/src/components/ui/rich-text-content.tsx b/src/components/ui/rich-text-content.tsx new file mode 100644 index 0000000..ba5f3a6 --- /dev/null +++ b/src/components/ui/rich-text-content.tsx @@ -0,0 +1,33 @@ +import { cn } from "../../lib/utils" +import { looksLikeHtml, stripHtml } from "../../lib/richText" + +export interface RichTextContentProps { + html?: string | null + className?: string + emptyLabel?: string +} + +export function RichTextContent({ + html, + className, + emptyLabel = "—", +}: RichTextContentProps) { + const trimmed = html?.trim() ?? "" + if (!trimmed) { + return {emptyLabel} + } + + if (looksLikeHtml(trimmed)) { + return ( +
+ ) + } + + return {stripHtml(trimmed)} +} diff --git a/src/components/ui/rich-text-editor.tsx b/src/components/ui/rich-text-editor.tsx new file mode 100644 index 0000000..0fc2693 --- /dev/null +++ b/src/components/ui/rich-text-editor.tsx @@ -0,0 +1,185 @@ +import { useEffect, type ReactNode } from "react" +import { EditorContent, useEditor } from "@tiptap/react" +import Placeholder from "@tiptap/extension-placeholder" +import StarterKit from "@tiptap/starter-kit" +import { + Bold, + Italic, + List, + ListOrdered, + Redo2, + Undo2, +} from "lucide-react" +import { cn } from "../../lib/utils" +import { richTextPlainLength } from "../../lib/richText" + +export interface RichTextEditorProps { + value?: string + onChange: (html: string) => void + placeholder?: string + maxLength?: number + className?: string + editorClassName?: string + disabled?: boolean +} + +function ToolbarButton({ + active, + disabled, + onClick, + label, + children, +}: { + active?: boolean + disabled?: boolean + onClick: () => void + label: string + children: ReactNode +}) { + return ( + + ) +} + +export function RichTextEditor({ + value = "", + onChange, + placeholder = "Write here…", + maxLength, + className, + editorClassName, + disabled = false, +}: RichTextEditorProps) { + const editor = useEditor({ + extensions: [ + StarterKit.configure({ + heading: false, + codeBlock: false, + blockquote: false, + horizontalRule: false, + }), + Placeholder.configure({ placeholder }), + ], + content: value || "", + editable: !disabled, + onUpdate: ({ editor: currentEditor }) => { + const html = currentEditor.getHTML() + if (maxLength != null && richTextPlainLength(html) > maxLength) { + currentEditor.commands.setContent(value || "", { emitUpdate: false }) + return + } + onChange(html === "

" ? "" : html) + }, + editorProps: { + attributes: { + class: cn( + "min-h-[120px] px-4 py-3 text-sm leading-relaxed text-grayScale-800 outline-none", + "prose prose-sm max-w-none prose-p:my-2 prose-ul:my-2 prose-ol:my-2", + editorClassName, + ), + }, + }, + }) + + useEffect(() => { + if (!editor) return + const current = editor.getHTML() + const normalizedCurrent = current === "

" ? "" : current + const normalizedValue = value || "" + if (normalizedCurrent !== normalizedValue) { + editor.commands.setContent(normalizedValue || "", { emitUpdate: false }) + } + }, [editor, value]) + + useEffect(() => { + if (!editor) return + editor.setEditable(!disabled) + }, [editor, disabled]) + + const plainLength = richTextPlainLength(value) + const atLimit = maxLength != null && plainLength >= maxLength + + return ( +
+
+ editor?.chain().focus().toggleBold().run()} + > + + + editor?.chain().focus().toggleItalic().run()} + > + + + editor?.chain().focus().toggleBulletList().run()} + > + + + editor?.chain().focus().toggleOrderedList().run()} + > + + +
+ editor?.chain().focus().undo().run()} + > + + + editor?.chain().focus().redo().run()} + > + + + {maxLength != null ? ( + + {plainLength} / {maxLength} + + ) : null} +
+ +
+ ) +} diff --git a/src/index.css b/src/index.css index 424a659..eb6e491 100644 --- a/src/index.css +++ b/src/index.css @@ -516,3 +516,11 @@ opacity: 0.8; } } + +.tiptap p.is-editor-empty:first-child::before { + color: rgb(148 163 184); + content: attr(data-placeholder); + float: left; + height: 0; + pointer-events: none; +} diff --git a/src/lib/richText.ts b/src/lib/richText.ts new file mode 100644 index 0000000..13d719c --- /dev/null +++ b/src/lib/richText.ts @@ -0,0 +1,18 @@ +export function stripHtml(html: string): string { + if (!html.trim()) return "" + const doc = new DOMParser().parseFromString(html, "text/html") + return (doc.body.textContent ?? "").replace(/\u00a0/g, " ").trim() +} + +export function hasRichTextContent(html: string | undefined | null): boolean { + return stripHtml(html ?? "").length > 0 +} + +export function richTextPlainLength(html: string | undefined | null): number { + return stripHtml(html ?? "").length +} + +export function looksLikeHtml(value: string | undefined | null): boolean { + const trimmed = value?.trim() ?? "" + return /<[^>]+>/.test(trimmed) +} diff --git a/src/pages/content-management/AddPracticeFlow.tsx b/src/pages/content-management/AddPracticeFlow.tsx index 8738c3f..3860608 100644 --- a/src/pages/content-management/AddPracticeFlow.tsx +++ b/src/pages/content-management/AddPracticeFlow.tsx @@ -26,6 +26,7 @@ import { formatPracticeParentsSummary, validatePracticeParents, } from "../../lib/practiceParents"; +import { hasRichTextContent } from "../../lib/richText"; import { ContextStep } from "./components/practice-steps/ContextStep"; import { ScenarioStep } from "./components/practice-steps/ScenarioStep"; @@ -384,7 +385,7 @@ export function AddPracticeFlow() { return; } const createParents = buildCreatePracticeParentsPayload(parents); - if (!formData.title.trim() || !formData.description.trim()) { + if (!formData.title.trim() || !hasRichTextContent(formData.description)) { toast.error("Title and story description are required", { description: "Complete the first step before publishing.", }); diff --git a/src/pages/content-management/EditPracticeFlow.tsx b/src/pages/content-management/EditPracticeFlow.tsx index 4a87498..5f255d1 100644 --- a/src/pages/content-management/EditPracticeFlow.tsx +++ b/src/pages/content-management/EditPracticeFlow.tsx @@ -45,6 +45,7 @@ import { QuestionsStep } from "./components/practice-steps/QuestionsStep"; import { ReviewStep } from "./components/practice-steps/ReviewStep"; import { personaIdNumber } from "./components/practice-steps/constants"; import { useActivePersonas } from "../../hooks/useActivePersonas"; +import { hasRichTextContent } from "../../lib/richText"; const STEP_LABELS = ["Practice", "Persona", "Questions", "Review"] as const; @@ -448,7 +449,7 @@ export function EditPracticeFlow() { toast.error("Invalid practice", { description: "Missing practice id in the URL." }); return; } - if (!formData.title.trim() || !formData.description.trim()) { + if (!formData.title.trim() || !hasRichTextContent(formData.description)) { toast.error("Title and story description are required", { description: "Complete the first step before saving.", }); diff --git a/src/pages/content-management/components/practice-steps/ContextStep.tsx b/src/pages/content-management/components/practice-steps/ContextStep.tsx index a975dc0..7fbec84 100644 --- a/src/pages/content-management/components/practice-steps/ContextStep.tsx +++ b/src/pages/content-management/components/practice-steps/ContextStep.tsx @@ -4,12 +4,13 @@ import { ArrowRight, ChevronDown, ChevronUp, Loader2, Upload } from "lucide-reac import { Button } from "../../../../components/ui/button"; import { Card } from "../../../../components/ui/card"; import { Input } from "../../../../components/ui/input"; -import { Textarea } from "../../../../components/ui/textarea"; +import { RichTextEditor } from "../../../../components/ui/rich-text-editor"; import { toast } from "sonner"; import { uploadImageFile } from "../../../../api/files.api"; import type { PracticeParent, AuthoringProfile } from "../../../../types/course.types"; import { PracticeParentsField } from "./PracticeParentsField"; import { formatPracticeParentsSummary } from "../../../../lib/practiceParents"; +import { hasRichTextContent } from "../../../../lib/richText"; interface ContextStepProps { formData: { @@ -24,8 +25,6 @@ interface ContextStepProps { setFormData: (data: ContextStepProps["formData"]) => void; nextStep: () => void; onCancel: () => void; - /** Lesson-linked practice: no title, story description, or story image on step 1. */ - isLessonPractice?: boolean; lessonTitle?: string | null; parentSummary?: string | null; /** Learn English LMS — show multi-parent picker. */ @@ -49,7 +48,6 @@ export function ContextStep({ setFormData, nextStep, onCancel, - isLessonPractice = false, lessonTitle = null, parentSummary = null, showParentsEditor = false, @@ -75,16 +73,15 @@ export function ContextStep({ if (!url) throw new Error("Missing image URL from upload"); setFormData({ ...formData, storyImageUrl: url }); toast.success("Story image uploaded"); - } catch { - notifyApiError(err, "Could not upload story image"); + } catch (e) { + notifyApiError(e, "Could not upload story image"); } finally { setUploadingStory(false); } }; - const canContinue = isLessonPractice - ? true - : Boolean(formData.title?.trim()) && Boolean(formData.description?.trim()); + const canContinue = + Boolean(formData.title?.trim()) && hasRichTextContent(formData.description); const parentsSummary = formData.parents && formData.parents.length > 0 @@ -95,22 +92,20 @@ export function ContextStep({

- {isLessonPractice ? "Practice options" : "Practice details"} + Practice details

- {isLessonPractice ? ( + Story fields and question set options used when saving the practice. + {lessonTitle?.trim() ? ( <> - Story fields and question set options used when saving the practice. Linked to{" "} + {" "} + Linked to{" "} - {lessonTitle?.trim() || "the selected lesson"} + {lessonTitle.trim()} . - ) : ( - <> - Story fields and question set options used when saving the practice. - - )} + ) : null}

@@ -194,91 +189,84 @@ export function ContextStep({ ) ) : null} - {!isLessonPractice ? ( - <> -
- - - setFormData({ ...formData, title: e.target.value }) - } - placeholder="e.g. Module conversation drill" - className="h-11 rounded-xl border-grayScale-200" - /> -
+
+ + + setFormData({ ...formData, title: e.target.value }) + } + placeholder={ + lessonTitle?.trim() + ? `e.g. ${lessonTitle.trim()} practice` + : "e.g. Module conversation drill" + } + className="h-11 rounded-xl border-grayScale-200" + /> +
-
- -