sea-react-components 1.3.25 → 1.3.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/cards-list/index.d.ts.map +1 -1
- package/dist/components/cards-list/index.js +4 -3
- package/dist/components/comments-container/comment-item/index.d.ts.map +1 -1
- package/dist/components/comments-container/comment-item/index.js +11 -4
- package/dist/components/comments-container/comments-list/index.js +1 -1
- package/dist/components/comments-container/index.js +1 -1
- package/dist/components/comments-container copy/comment-event-bus/index.d.ts +4 -0
- package/dist/components/comments-container copy/comment-event-bus/index.d.ts.map +1 -0
- package/dist/components/comments-container copy/comment-event-bus/index.js +4 -0
- package/dist/components/comments-container copy/comment-form/index.d.ts +39 -0
- package/dist/components/comments-container copy/comment-form/index.d.ts.map +1 -0
- package/dist/components/comments-container copy/comment-form/index.js +83 -0
- package/dist/components/comments-container copy/comment-item/index.d.ts +13 -0
- package/dist/components/comments-container copy/comment-item/index.d.ts.map +1 -0
- package/dist/components/comments-container copy/comment-item/index.js +20 -0
- package/dist/components/comments-container copy/comments-list/index.d.ts +24 -0
- package/dist/components/comments-container copy/comments-list/index.d.ts.map +1 -0
- package/dist/components/comments-container copy/comments-list/index.js +35 -0
- package/dist/components/comments-container copy/constants/index.d.ts +5 -0
- package/dist/components/comments-container copy/constants/index.d.ts.map +1 -0
- package/dist/components/comments-container copy/constants/index.js +5 -0
- package/dist/components/comments-container copy/index.d.ts +21 -0
- package/dist/components/comments-container copy/index.d.ts.map +1 -0
- package/dist/components/comments-container copy/index.js +27 -0
- package/dist/components/comments-container copy/use-comments/index.d.ts +17 -0
- package/dist/components/comments-container copy/use-comments/index.d.ts.map +1 -0
- package/dist/components/comments-container copy/use-comments/index.js +59 -0
- package/dist/components/form/index.d.ts +13 -7
- package/dist/components/form/index.d.ts.map +1 -1
- package/dist/components/form/index.js +84 -3
- package/dist/components/icon/index.d.ts +3 -3
- package/dist/components/icon/index.d.ts.map +1 -1
- package/dist/components/icon/index.js +2 -2
- package/dist/components/list-item/index.d.ts.map +1 -1
- package/dist/components/list-item/index.js +2 -2
- package/dist/components/log-activities-container/activity-message/index.d.ts +7 -0
- package/dist/components/log-activities-container/activity-message/index.d.ts.map +1 -0
- package/dist/components/log-activities-container/activity-message/index.js +63 -0
- package/dist/components/log-activities-container/comment-event-bus/index.d.ts +4 -0
- package/dist/components/log-activities-container/comment-event-bus/index.d.ts.map +1 -0
- package/dist/components/log-activities-container/comment-event-bus/index.js +4 -0
- package/dist/components/log-activities-container/comment-form/index.d.ts +39 -0
- package/dist/components/log-activities-container/comment-form/index.d.ts.map +1 -0
- package/dist/components/log-activities-container/comment-form/index.js +83 -0
- package/dist/components/log-activities-container/comment-item/index.d.ts +13 -0
- package/dist/components/log-activities-container/comment-item/index.d.ts.map +1 -0
- package/dist/components/log-activities-container/comment-item/index.js +20 -0
- package/dist/components/log-activities-container/comments-list/index.d.ts +24 -0
- package/dist/components/log-activities-container/comments-list/index.d.ts.map +1 -0
- package/dist/components/log-activities-container/comments-list/index.js +35 -0
- package/dist/components/log-activities-container/constants/index.d.ts +5 -0
- package/dist/components/log-activities-container/constants/index.d.ts.map +1 -0
- package/dist/components/log-activities-container/constants/index.js +5 -0
- package/dist/components/log-activities-container/index.d.ts +10 -0
- package/dist/components/log-activities-container/index.d.ts.map +1 -0
- package/dist/components/log-activities-container/index.js +9 -0
- package/dist/components/log-activities-container/log-activities-list/index.d.ts +11 -0
- package/dist/components/log-activities-container/log-activities-list/index.d.ts.map +1 -0
- package/dist/components/log-activities-container/log-activities-list/index.js +13 -0
- package/dist/components/log-activities-container/log-activity-item/index.d.ts +7 -0
- package/dist/components/log-activities-container/log-activity-item/index.d.ts.map +1 -0
- package/dist/components/log-activities-container/log-activity-item/index.js +63 -0
- package/dist/components/log-activities-container/use-comments/index.d.ts +17 -0
- package/dist/components/log-activities-container/use-comments/index.d.ts.map +1 -0
- package/dist/components/log-activities-container/use-comments/index.js +59 -0
- package/dist/components/log-activities-container/use-log-activities/index.d.ts +14 -0
- package/dist/components/log-activities-container/use-log-activities/index.d.ts.map +1 -0
- package/dist/components/log-activities-container/use-log-activities/index.js +41 -0
- package/dist/components/modal/index.js +1 -1
- package/dist/components/native-menu/index.d.ts +3 -1
- package/dist/components/native-menu/index.d.ts.map +1 -1
- package/dist/components/native-menu/index.js +22 -4
- package/dist/components/native-menu/native-menu-item/index.js +1 -1
- package/dist/components/notifications-menu/index.d.ts.map +1 -1
- package/dist/components/notifications-menu/index.js +53 -10
- package/dist/components/radio-button/index.d.ts +4 -8
- package/dist/components/radio-button/index.d.ts.map +1 -1
- package/dist/components/radio-button/index.js +3 -2
- package/dist/components/select/index.d.ts +2 -1
- package/dist/components/select/index.d.ts.map +1 -1
- package/dist/components/select/index.js +2 -2
- package/dist/components/tab/index.d.ts.map +1 -1
- package/dist/components/tab/index.js +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +1 -0
- package/dist/services/remote-action/index.d.ts +14 -0
- package/dist/services/remote-action/index.d.ts.map +1 -0
- package/dist/services/remote-action/index.js +21 -0
- package/dist/services/remote-service/index.d.ts +31 -0
- package/dist/services/remote-service/index.d.ts.map +1 -0
- package/dist/services/remote-service/index.js +45 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/axios/index.d.ts +1 -0
- package/dist/utils/axios/index.d.ts.map +1 -1
- package/dist/utils/axios/index.js +7 -2
- package/dist/utils/remote-action/index.d.ts +14 -0
- package/dist/utils/remote-action/index.d.ts.map +1 -0
- package/dist/utils/remote-action/index.js +21 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/cards-list/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,eAAO,MAAM,wCAAwC;;;GAKpD,CAAC;AAEF,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI;IACrB,IAAI,EAAE,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IAC7B,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAClD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;QAAE,GAAG,EAAE;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,GAAG,CAAC,CAAA;KAAE,CAAC,GAAG,SAAS,CAAC;IAClE,OAAO,CAAC,EAAE;QACR,gBAAgB,EAAE,MAAM,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AACF,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,CAAC,EAAE,EACnC,aAAa,EACb,IAAI,EACJ,iBAAiB,EACjB,OAGC,EACD,OAAe,GAChB,EAAE,KAAK,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/cards-list/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AAGtE,eAAO,MAAM,wCAAwC;;;GAKpD,CAAC;AAEF,MAAM,MAAM,KAAK,CAAC,CAAC,IAAI;IACrB,IAAI,EAAE,CAAC;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IAC7B,iBAAiB,CAAC,EAAE,iBAAiB,GAAG,SAAS,CAAC;IAClD,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,aAAa,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;QAAE,GAAG,EAAE;YAAE,EAAE,EAAE,MAAM,CAAA;SAAE,GAAG,CAAC,CAAA;KAAE,CAAC,GAAG,SAAS,CAAC;IAClE,OAAO,CAAC,EAAE;QACR,gBAAgB,EAAE,MAAM,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;CACH,CAAC;AACF,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,CAAC,EAAE,EACnC,aAAa,EACb,IAAI,EACJ,iBAAiB,EACjB,OAGC,EACD,OAAe,GAChB,EAAE,KAAK,CAAC,CAAC,CAAC,2CAuCV"}
|
|
@@ -8,10 +8,11 @@ export const DEFAULT_CARDS_LIST_ROWS_PER_PAGE_OPTIONS = [4, 8, 12, 16].map((item
|
|
|
8
8
|
value: item,
|
|
9
9
|
}));
|
|
10
10
|
export default function CardsList({ CardComponent, rows, bulkActionFeature, classes = {
|
|
11
|
-
containerClasses: "grid grid-cols-4 gap-4",
|
|
12
|
-
cardClasses: "col-span-4 md:col-span-2
|
|
11
|
+
containerClasses: "grid grid-cols-4 gap-2 md:gap-4",
|
|
12
|
+
cardClasses: "col-span-4 md:col-span-2 col-span-1",
|
|
13
13
|
}, loading = false, }) {
|
|
14
|
-
|
|
14
|
+
console.log({ rows });
|
|
15
|
+
return (_jsx("div", { children: loading ? (_jsx("div", { className: "flex items-center justify-center", children: _jsx(Loader, {}) })) : (_jsx("div", { className: clsx(classes.containerClasses), children: rows.map((row) => (_jsxs("div", { className: clsx(classes.cardClasses), children: [bulkActionFeature && (_jsx(Checkbox, { checked: bulkActionFeature.selectedRowIds.length === rows.length, onChange: (checked) => {
|
|
15
16
|
if (checked) {
|
|
16
17
|
bulkActionFeature.setSelectedRowIds(rows.map((r) => r.id));
|
|
17
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/comments-container/comment-item/index.tsx"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/comments-container/comment-item/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,GAAG,EAAS,MAAM,sBAAsB,CAAC;AAK7D,MAAM,MAAM,KAAK,GAAG;IAClB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;IACpE,WAAW,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;IACjE,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,OAAO,EACP,WAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,eAAe,EACf,QAAQ,EACR,KAAK,GACN,EAAE,KAAK,2CAkHP"}
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useState } from "react";
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
4
|
import clsx from "clsx";
|
|
5
|
-
import { Utils } from "sea-platform-helpers";
|
|
5
|
+
import { CONSTANTS, Utils } from "sea-platform-helpers";
|
|
6
6
|
import Icon from "../../icon";
|
|
7
7
|
import Avatar from "../../avatar";
|
|
8
8
|
import CommentsList from "../comments-list";
|
|
9
9
|
export default function CommentItem({ comment, isHighlight = false, currentAccountId, replyOnComment, editComment, commentsBaseUrl, objectId, limit, }) {
|
|
10
10
|
var _a, _b;
|
|
11
|
-
const [isReplyListOpen, setIsReplyListOpen] = useState(
|
|
12
|
-
|
|
11
|
+
const [isReplyListOpen, setIsReplyListOpen] = useState(true);
|
|
12
|
+
const highlightedCommentId = useMemo(() => {
|
|
13
|
+
if (typeof window === "undefined")
|
|
14
|
+
return null;
|
|
15
|
+
const params = new URLSearchParams(window.location.search);
|
|
16
|
+
return params.get(CONSTANTS.Routes.global.QUERY_PARAMETER_KEYS.HIGHLIGHTED_COMMENT_ID);
|
|
17
|
+
}, []);
|
|
18
|
+
const shouldHighlight = isHighlight || comment.id === highlightedCommentId;
|
|
19
|
+
return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("div", { className: clsx("relative flex flex-col gap-2 p-2 border border-gray-100 rounded-lg bg-white shadow-sm transition-all", shouldHighlight && "ring-2 ring-primary/50 bg-primary/5"), children: _jsxs("div", { className: "flex items-start gap-3", children: [_jsx(Avatar, { alt: ((_a = comment.account) === null || _a === void 0 ? void 0 : _a.name) || "", placeholderSource: "letters", size: "sm" }), _jsxs("div", { className: "flex flex-col flex-1 gap-1", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("p", { className: "text-sm font-semibold text-gray-900", children: (_b = comment.account) === null || _b === void 0 ? void 0 : _b.name }), _jsx("p", { className: "text-xs text-gray-500", children: Utils.Moment.formatDateAsLabel(comment.createdAt) })] }), _jsx("p", { className: "text-sm text-gray-700 leading-relaxed", children: comment.description }), comment.edited && (_jsxs("p", { className: "text-xs text-info italic", children: ["(Edited ", Utils.Moment.formatDateAsLabel(comment.updatedAt), ")"] })), _jsxs("div", { className: "flex items-center gap-4 text-xs text-gray-500", children: [comment.account && currentAccountId === comment.account.id && (_jsxs("button", { type: "button", onClick: () => editComment(comment), className: "flex items-center gap-1 hover:text-info transition", children: [_jsx(Icon, { icon: "bitcoin-icons:edit-outline", className: "h-4 w-4" }), _jsx("span", { children: "Edit" })] })), _jsxs("button", { type: "button", onClick: () => replyOnComment(comment), className: "flex items-center gap-1 hover:text-success transition", children: [_jsx(Icon, { icon: "basil:reply-outline", className: "h-4 w-4" }), _jsx("span", { children: "Reply" })] }), comment.repliesCount > 0 && (_jsxs("button", { type: "button", onClick: () => setIsReplyListOpen((prev) => !prev), className: "flex items-center gap-1 hover:text-info transition", children: [_jsx(Icon, { icon: isReplyListOpen ? "mdi:chevron-up" : "mdi:chevron-down", className: "h-4 w-4" }), _jsxs("span", { children: [comment.repliesCount, " replies"] })] }))] })] })] }) }), comment.repliesCount !== 0 && isReplyListOpen && (_jsx("div", { className: "pl-4 mt-1", children: _jsx(CommentsList, { editComment: editComment, replyOnComment: replyOnComment, highlightCommentId: isHighlight ? comment.id : "", currentAccountId: currentAccountId, commentsBaseUrl: commentsBaseUrl, objectId: objectId, limit: limit, parentCommentId: comment.id }) }))] }));
|
|
13
20
|
}
|
|
@@ -21,7 +21,7 @@ export default function CommentsList({ currentAccountId, highlightCommentId, edi
|
|
|
21
21
|
eventBus.off(COMMENT_EVENTS.UpdateComment, handleUpdateComment);
|
|
22
22
|
};
|
|
23
23
|
}, []);
|
|
24
|
-
return (_jsx("div", { className: clsx("flex flex-col", isReplyList ? "gap-2" : "gap-4"), children: comments.length === 0 && !loading ? (_jsx("p", { className: "text-gray-500 text-sm text-center py-4", children: "There are no comments yet" })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "flex flex-col gap-
|
|
24
|
+
return (_jsx("div", { className: clsx("flex flex-col", isReplyList ? "gap-2" : "gap-4"), children: comments.length === 0 && !loading ? (_jsx("p", { className: "text-gray-500 text-sm text-center py-4", children: "There are no comments yet" })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "flex flex-col gap-2", children: comments.map((comment) => renderCommentItem ? (renderCommentItem(comment, {
|
|
25
25
|
currentAccountId,
|
|
26
26
|
editComment,
|
|
27
27
|
replyOnComment,
|
|
@@ -17,7 +17,7 @@ export default function CommentsContainer({ commentsBaseUrl, objectId, model, li
|
|
|
17
17
|
const payload = (_b = jwtDecode(accessToken)) !== null && _b !== void 0 ? _b : null;
|
|
18
18
|
setAccountId((payload === null || payload === void 0 ? void 0 : payload.id) || "");
|
|
19
19
|
}, []);
|
|
20
|
-
return (_jsxs("div", { className: "flex flex-col gap-
|
|
20
|
+
return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(CommentForm, { commentsBaseUrl: commentsBaseUrl, objectId: objectId, model: model, commentToEdit: commentToEdit, setCommentToEdit: setCommentToEdit, replyOnComment: replyOnComment, setReplyOnComment: setReplyOnComment, onCreateCommentSuccess: () => {
|
|
21
21
|
setCommentToEdit(undefined);
|
|
22
22
|
setReplyOnComment(undefined);
|
|
23
23
|
}, onEditCommentSuccess: () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/comments-container copy/comment-event-bus/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,QAAA,MAAM,QAAQ,uBAAqB,CAAC;AAEpC,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { useFormik } from "formik";
|
|
3
|
+
import { DTO } from "sea-platform-helpers";
|
|
4
|
+
import * as Yup from "yup";
|
|
5
|
+
export declare const createNewCommentValidation: () => Yup.ObjectSchema<{
|
|
6
|
+
description: string;
|
|
7
|
+
}, Yup.AnyObject, {
|
|
8
|
+
description: undefined;
|
|
9
|
+
}, "">;
|
|
10
|
+
type Values = {
|
|
11
|
+
objectId: string;
|
|
12
|
+
model: DTO.Comment.CommentSupportedModels;
|
|
13
|
+
description: string;
|
|
14
|
+
parentCommentId?: string;
|
|
15
|
+
};
|
|
16
|
+
export type CommentFormRenderProps = {
|
|
17
|
+
formik: ReturnType<typeof useFormik<Values>>;
|
|
18
|
+
isReplying: boolean;
|
|
19
|
+
isEditing: boolean;
|
|
20
|
+
replyOnComment?: DTO.Comment.IComment;
|
|
21
|
+
cancelReply: () => void;
|
|
22
|
+
cancelEdit: () => void;
|
|
23
|
+
handleKeyDown?: (e: React.KeyboardEvent<HTMLTextAreaElement>) => void;
|
|
24
|
+
};
|
|
25
|
+
export type Props = {
|
|
26
|
+
objectId: string;
|
|
27
|
+
model: DTO.Comment.CommentSupportedModels;
|
|
28
|
+
commentsBaseUrl: string;
|
|
29
|
+
commentToEdit?: DTO.Comment.IComment;
|
|
30
|
+
setCommentToEdit: (comment: DTO.Comment.IComment | undefined) => void;
|
|
31
|
+
replyOnComment?: DTO.Comment.IComment;
|
|
32
|
+
setReplyOnComment: (comment: DTO.Comment.IComment | undefined) => void;
|
|
33
|
+
onCreateCommentSuccess?: (comment: DTO.Comment.IComment) => void;
|
|
34
|
+
onEditCommentSuccess?: (comment: DTO.Comment.IComment) => void;
|
|
35
|
+
renderForm?: (props: CommentFormRenderProps) => React.ReactNode;
|
|
36
|
+
};
|
|
37
|
+
export default function CommentForm({ objectId, model, commentsBaseUrl, commentToEdit, setCommentToEdit, replyOnComment, setReplyOnComment, onCreateCommentSuccess, onEditCommentSuccess, renderForm, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
38
|
+
export {};
|
|
39
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/comments-container copy/comment-form/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,OAAO,EAAiB,SAAS,EAAE,MAAM,QAAQ,CAAC;AAClD,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAC3C,OAAO,KAAK,GAAG,MAAM,KAAK,CAAC;AAK3B,eAAO,MAAM,0BAA0B;;;;MAQtC,CAAC;AAEF,KAAK,MAAM,GAAG;IACZ,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,sBAAsB,CAAC;IAC1C,WAAW,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,UAAU,CAAC,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7C,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IACtC,WAAW,EAAE,MAAM,IAAI,CAAC;IACxB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,aAAa,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAC;CACvE,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,sBAAsB,CAAC;IAC1C,eAAe,EAAE,MAAM,CAAC;IAExB,aAAa,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IACrC,gBAAgB,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;IAEtE,cAAc,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IACtC,iBAAiB,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;IAEvE,sBAAsB,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,IAAI,CAAC;IACjE,oBAAoB,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,KAAK,IAAI,CAAC;IAE/D,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,KAAK,CAAC,SAAS,CAAC;CACjE,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,QAAQ,EACR,KAAK,EACL,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,sBAAsB,EACtB,oBAAoB,EACpB,UAAU,GACX,EAAE,KAAK,2CAsIP"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import Textarea from "../../textarea";
|
|
4
|
+
import Button from "../../button";
|
|
5
|
+
import { useFormik } from "formik";
|
|
6
|
+
import * as Yup from "yup";
|
|
7
|
+
import { authAxiosInstance } from "../../../utils/auth-axios";
|
|
8
|
+
import eventBus from "../comment-event-bus";
|
|
9
|
+
import { COMMENT_EVENTS } from "../constants";
|
|
10
|
+
export const createNewCommentValidation = () => {
|
|
11
|
+
return Yup.object({
|
|
12
|
+
description: Yup.string()
|
|
13
|
+
.trim()
|
|
14
|
+
.min(1, "Required")
|
|
15
|
+
.max(1000, "Must be at most 1000 characters")
|
|
16
|
+
.required("Required"),
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export default function CommentForm({ objectId, model, commentsBaseUrl, commentToEdit, setCommentToEdit, replyOnComment, setReplyOnComment, onCreateCommentSuccess, onEditCommentSuccess, renderForm, }) {
|
|
20
|
+
var _a;
|
|
21
|
+
const initialValues = {
|
|
22
|
+
model,
|
|
23
|
+
objectId,
|
|
24
|
+
description: (commentToEdit === null || commentToEdit === void 0 ? void 0 : commentToEdit.description) || "",
|
|
25
|
+
parentCommentId: (replyOnComment === null || replyOnComment === void 0 ? void 0 : replyOnComment.id) || "",
|
|
26
|
+
};
|
|
27
|
+
const onSubmit = async (values, helpers) => {
|
|
28
|
+
try {
|
|
29
|
+
if (commentToEdit) {
|
|
30
|
+
const response = await authAxiosInstance.put(`${commentsBaseUrl}/${commentToEdit.id}`, { description: values.description });
|
|
31
|
+
eventBus.emit(COMMENT_EVENTS.UpdateComment, response.data);
|
|
32
|
+
onEditCommentSuccess === null || onEditCommentSuccess === void 0 ? void 0 : onEditCommentSuccess(response.data);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const response = await authAxiosInstance.post(commentsBaseUrl, {
|
|
36
|
+
objectId: values.objectId,
|
|
37
|
+
model: values.model,
|
|
38
|
+
description: values.description,
|
|
39
|
+
parentCommentId: values.parentCommentId,
|
|
40
|
+
});
|
|
41
|
+
eventBus.emit(COMMENT_EVENTS.NewComment, response.data);
|
|
42
|
+
onCreateCommentSuccess === null || onCreateCommentSuccess === void 0 ? void 0 : onCreateCommentSuccess(response.data);
|
|
43
|
+
}
|
|
44
|
+
helpers.resetForm();
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
helpers.setSubmitting(false);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const formik = useFormik({
|
|
51
|
+
initialValues,
|
|
52
|
+
validationSchema: createNewCommentValidation,
|
|
53
|
+
onSubmit,
|
|
54
|
+
enableReinitialize: true,
|
|
55
|
+
});
|
|
56
|
+
const handleKeyDown = (e) => {
|
|
57
|
+
// If user pressed Ctrl+Enter (Windows/Linux) or Cmd+Enter (Mac)
|
|
58
|
+
if ((e.ctrlKey || e.metaKey) && e.key === "Enter") {
|
|
59
|
+
e.preventDefault(); // prevent new line
|
|
60
|
+
if (!formik.isSubmitting && formik.isValid) {
|
|
61
|
+
formik.submitForm();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const cancelReply = () => setReplyOnComment(undefined);
|
|
66
|
+
const cancelEdit = () => setCommentToEdit(undefined);
|
|
67
|
+
const renderProps = {
|
|
68
|
+
formik,
|
|
69
|
+
isReplying: Boolean(replyOnComment),
|
|
70
|
+
isEditing: Boolean(commentToEdit),
|
|
71
|
+
replyOnComment,
|
|
72
|
+
cancelReply,
|
|
73
|
+
cancelEdit,
|
|
74
|
+
handleKeyDown,
|
|
75
|
+
};
|
|
76
|
+
if (renderForm)
|
|
77
|
+
return _jsx(_Fragment, { children: renderForm(renderProps) });
|
|
78
|
+
return (_jsxs("form", { onSubmit: formik.handleSubmit, className: "flex flex-col gap-3", children: [replyOnComment && (_jsxs("div", { className: "flex items-center justify-between bg-primary/5 px-3 py-2 rounded-lg border border-primary/10", children: [_jsxs("p", { className: "text-sm text-gray-700", children: ["Replying to", " ", _jsx("span", { className: "font-semibold text-primary", children: (_a = replyOnComment.account) === null || _a === void 0 ? void 0 : _a.name })] }), _jsx(Button, { type: "button", onClick: () => setReplyOnComment(undefined), className: "bg-transparent", children: _jsx("p", { className: "text-error hover:text-opacity-75 custom-animation", children: "Cancel" }) })] })), _jsx(Textarea, { name: "description", placeholder: commentToEdit
|
|
79
|
+
? "Edit your comment..."
|
|
80
|
+
: replyOnComment
|
|
81
|
+
? "Write a reply..."
|
|
82
|
+
: "Add a comment...", onChange: formik.handleChange, onBlur: formik.handleBlur, value: formik.values.description, errorMessage: formik.touched.description ? formik.errors.description : "", className: "min-h-[80px]", onKeyDown: handleKeyDown }), _jsxs("div", { className: "flex justify-end gap-2 pt-1", children: [commentToEdit && (_jsx(Button, { type: "button", onClick: () => setCommentToEdit(undefined), className: "bg-transparent", children: _jsx("p", { className: "text-error hover:text-opacity-75 custom-animation", children: "Cancel" }) })), _jsx(Button, { type: "submit", loading: formik.isSubmitting, disabled: formik.isSubmitting || !formik.isValid, children: commentToEdit ? "Update Comment" : "Add Comment" })] })] }));
|
|
83
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DTO } from "sea-platform-helpers";
|
|
2
|
+
export type Props = {
|
|
3
|
+
comment: DTO.Comment.IComment;
|
|
4
|
+
isHighlight?: boolean;
|
|
5
|
+
currentAccountId?: string;
|
|
6
|
+
replyOnComment: (comment: DTO.Comment.IComment | undefined) => void;
|
|
7
|
+
editComment: (comment: DTO.Comment.IComment | undefined) => void;
|
|
8
|
+
commentsBaseUrl: string;
|
|
9
|
+
objectId: string;
|
|
10
|
+
limit?: number;
|
|
11
|
+
};
|
|
12
|
+
export default function CommentItem({ comment, isHighlight, currentAccountId, replyOnComment, editComment, commentsBaseUrl, objectId, limit, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/comments-container copy/comment-item/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAa,GAAG,EAAS,MAAM,sBAAsB,CAAC;AAK7D,MAAM,MAAM,KAAK,GAAG;IAClB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC9B,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;IACpE,WAAW,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;IACjE,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,OAAO,EACP,WAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,eAAe,EACf,QAAQ,EACR,KAAK,GACN,EAAE,KAAK,2CAkHP"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import { CONSTANTS, Utils } from "sea-platform-helpers";
|
|
6
|
+
import Icon from "../../icon";
|
|
7
|
+
import Avatar from "../../avatar";
|
|
8
|
+
import CommentsList from "../comments-list";
|
|
9
|
+
export default function CommentItem({ comment, isHighlight = false, currentAccountId, replyOnComment, editComment, commentsBaseUrl, objectId, limit, }) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const [isReplyListOpen, setIsReplyListOpen] = useState(true);
|
|
12
|
+
const highlightedCommentId = useMemo(() => {
|
|
13
|
+
if (typeof window === "undefined")
|
|
14
|
+
return null;
|
|
15
|
+
const params = new URLSearchParams(window.location.search);
|
|
16
|
+
return params.get(CONSTANTS.Routes.global.QUERY_PARAMETER_KEYS.HIGHLIGHTED_COMMENT_ID);
|
|
17
|
+
}, []);
|
|
18
|
+
const shouldHighlight = isHighlight || comment.id === highlightedCommentId;
|
|
19
|
+
return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx("div", { className: clsx("relative flex flex-col gap-2 p-2 border border-gray-100 rounded-lg bg-white shadow-sm transition-all", shouldHighlight && "ring-2 ring-primary/50 bg-primary/5"), children: _jsxs("div", { className: "flex items-start gap-3", children: [_jsx(Avatar, { alt: ((_a = comment.account) === null || _a === void 0 ? void 0 : _a.name) || "", placeholderSource: "letters", size: "sm" }), _jsxs("div", { className: "flex flex-col flex-1 gap-1", children: [_jsxs("div", { className: "flex items-center justify-between", children: [_jsx("p", { className: "text-sm font-semibold text-gray-900", children: (_b = comment.account) === null || _b === void 0 ? void 0 : _b.name }), _jsx("p", { className: "text-xs text-gray-500", children: Utils.Moment.formatDateAsLabel(comment.createdAt) })] }), _jsx("p", { className: "text-sm text-gray-700 leading-relaxed", children: comment.description }), comment.edited && (_jsxs("p", { className: "text-xs text-info italic", children: ["(Edited ", Utils.Moment.formatDateAsLabel(comment.updatedAt), ")"] })), _jsxs("div", { className: "flex items-center gap-4 text-xs text-gray-500", children: [comment.account && currentAccountId === comment.account.id && (_jsxs("button", { type: "button", onClick: () => editComment(comment), className: "flex items-center gap-1 hover:text-info transition", children: [_jsx(Icon, { icon: "bitcoin-icons:edit-outline", className: "h-4 w-4" }), _jsx("span", { children: "Edit" })] })), _jsxs("button", { type: "button", onClick: () => replyOnComment(comment), className: "flex items-center gap-1 hover:text-success transition", children: [_jsx(Icon, { icon: "basil:reply-outline", className: "h-4 w-4" }), _jsx("span", { children: "Reply" })] }), comment.repliesCount > 0 && (_jsxs("button", { type: "button", onClick: () => setIsReplyListOpen((prev) => !prev), className: "flex items-center gap-1 hover:text-info transition", children: [_jsx(Icon, { icon: isReplyListOpen ? "mdi:chevron-up" : "mdi:chevron-down", className: "h-4 w-4" }), _jsxs("span", { children: [comment.repliesCount, " replies"] })] }))] })] })] }) }), comment.repliesCount !== 0 && isReplyListOpen && (_jsx("div", { className: "pl-4 mt-1", children: _jsx(CommentsList, { editComment: editComment, replyOnComment: replyOnComment, highlightCommentId: isHighlight ? comment.id : "", currentAccountId: currentAccountId, commentsBaseUrl: commentsBaseUrl, objectId: objectId, limit: limit, parentCommentId: comment.id }) }))] }));
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { DTO } from "sea-platform-helpers";
|
|
3
|
+
type Props = {
|
|
4
|
+
currentAccountId?: string;
|
|
5
|
+
highlightCommentId?: string;
|
|
6
|
+
editComment: (comment: DTO.Comment.IComment | undefined) => void;
|
|
7
|
+
replyOnComment: (comment: DTO.Comment.IComment | undefined) => void;
|
|
8
|
+
commentsBaseUrl: string;
|
|
9
|
+
objectId: string;
|
|
10
|
+
limit?: number;
|
|
11
|
+
parentCommentId?: string;
|
|
12
|
+
renderCommentItem?: (comment: DTO.Comment.IComment, commonProps: {
|
|
13
|
+
currentAccountId?: string;
|
|
14
|
+
editComment: (comment: DTO.Comment.IComment | undefined) => void;
|
|
15
|
+
replyOnComment: (comment: DTO.Comment.IComment | undefined) => void;
|
|
16
|
+
commentsBaseUrl: string;
|
|
17
|
+
objectId: string;
|
|
18
|
+
limit?: number;
|
|
19
|
+
highlightCommentId?: string;
|
|
20
|
+
}) => React.ReactNode;
|
|
21
|
+
};
|
|
22
|
+
export default function CommentsList({ currentAccountId, highlightCommentId, editComment, replyOnComment, commentsBaseUrl, objectId, parentCommentId, limit, renderCommentItem, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/comments-container copy/comments-list/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAEzC,OAAO,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAQ3C,KAAK,KAAK,GAAG;IACX,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,WAAW,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;IACjE,cAAc,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;IACpE,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,iBAAiB,CAAC,EAAE,CAClB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,EAC7B,WAAW,EAAE;QACX,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,WAAW,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;QACjE,cAAc,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;QACpE,eAAe,EAAE,MAAM,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC7B,KACE,KAAK,CAAC,SAAS,CAAC;CACtB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,gBAAgB,EAChB,kBAAkB,EAClB,WAAW,EACX,cAAc,EACd,eAAe,EACf,QAAQ,EACR,eAAe,EACf,KAAU,EACV,iBAAiB,GAClB,EAAE,KAAK,2CAgGP"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import Skeleton from "../../skeleton";
|
|
5
|
+
import CommentItem from "../comment-item";
|
|
6
|
+
import Button from "../../button";
|
|
7
|
+
import { useComments } from "../use-comments";
|
|
8
|
+
import eventBus from "../comment-event-bus";
|
|
9
|
+
import { COMMENT_EVENTS } from "../constants";
|
|
10
|
+
import clsx from "clsx";
|
|
11
|
+
export default function CommentsList({ currentAccountId, highlightCommentId, editComment, replyOnComment, commentsBaseUrl, objectId, parentCommentId, limit = 10, renderCommentItem, }) {
|
|
12
|
+
const { comments, loading, totalCount, pushNewComment, updateComment, loadMoreComments, hasMoreComments, } = useComments({ commentsBaseUrl, objectId, limit, parentCommentId });
|
|
13
|
+
const isReplyList = Boolean(parentCommentId);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
const handleNewComment = (data) => pushNewComment(data);
|
|
16
|
+
const handleUpdateComment = (data) => updateComment(data);
|
|
17
|
+
eventBus.on(COMMENT_EVENTS.NewComment, handleNewComment);
|
|
18
|
+
eventBus.on(COMMENT_EVENTS.UpdateComment, handleUpdateComment);
|
|
19
|
+
return () => {
|
|
20
|
+
eventBus.off(COMMENT_EVENTS.NewComment, handleNewComment);
|
|
21
|
+
eventBus.off(COMMENT_EVENTS.UpdateComment, handleUpdateComment);
|
|
22
|
+
};
|
|
23
|
+
}, []);
|
|
24
|
+
return (_jsx("div", { className: clsx("flex flex-col", isReplyList ? "gap-2" : "gap-4"), children: comments.length === 0 && !loading ? (_jsx("p", { className: "text-gray-500 text-sm text-center py-4", children: "There are no comments yet" })) : (_jsxs(_Fragment, { children: [_jsx("div", { className: "flex flex-col gap-2", children: comments.map((comment) => renderCommentItem ? (renderCommentItem(comment, {
|
|
25
|
+
currentAccountId,
|
|
26
|
+
editComment,
|
|
27
|
+
replyOnComment,
|
|
28
|
+
commentsBaseUrl,
|
|
29
|
+
objectId,
|
|
30
|
+
limit,
|
|
31
|
+
highlightCommentId,
|
|
32
|
+
})) : (_jsx(CommentItem, { comment: comment, isHighlight: highlightCommentId === comment.id, currentAccountId: currentAccountId, editComment: editComment, replyOnComment: replyOnComment, commentsBaseUrl: commentsBaseUrl, objectId: objectId, limit: limit }, comment.id))) }), loading && (_jsx("div", { className: "flex flex-col gap-3", children: Array(3)
|
|
33
|
+
.fill(null)
|
|
34
|
+
.map((_, i) => (_jsx(Skeleton, { className: "h-20 w-full rounded-lg" }, `comment-loading-${i}`))) })), totalCount !== 0 && !isReplyList && (_jsxs("p", { className: "text-gray-500 text-xs text-right mt-1", children: ["Showing ", comments.length, " of ", totalCount, " comments"] })), hasMoreComments && !loading && (_jsx("div", { className: clsx("flex justify-center mt-2"), children: _jsx(Button, { type: "button", onClick: loadMoreComments, variant: "secondary", children: "Load More" }) }))] })) }));
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/comments-container copy/constants/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc;;;CAG1B,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DTO } from "sea-platform-helpers";
|
|
2
|
+
import { CommentFormRenderProps } from "./comment-form";
|
|
3
|
+
export type Props = {
|
|
4
|
+
commentsBaseUrl: string;
|
|
5
|
+
objectId: string;
|
|
6
|
+
model: DTO.Comment.CommentSupportedModels;
|
|
7
|
+
limit?: number;
|
|
8
|
+
highlightCommentId?: string;
|
|
9
|
+
renderCommentItem?: (comment: DTO.Comment.IComment, commonProps: {
|
|
10
|
+
currentAccountId?: string;
|
|
11
|
+
editComment: (comment: DTO.Comment.IComment | undefined) => void;
|
|
12
|
+
replyOnComment: (comment: DTO.Comment.IComment | undefined) => void;
|
|
13
|
+
commentsBaseUrl: string;
|
|
14
|
+
objectId: string;
|
|
15
|
+
limit?: number;
|
|
16
|
+
highlightCommentId?: string;
|
|
17
|
+
}) => React.ReactNode;
|
|
18
|
+
renderForm?: (props: CommentFormRenderProps) => React.ReactNode;
|
|
19
|
+
};
|
|
20
|
+
export default function CommentsContainer({ commentsBaseUrl, objectId, model, limit, highlightCommentId, renderCommentItem, renderForm, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/comments-container copy/index.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAa,MAAM,sBAAsB,CAAC;AAItD,OAAoB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAIrE,MAAM,MAAM,KAAK,GAAG;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,GAAG,CAAC,OAAO,CAAC,sBAAsB,CAAC;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,iBAAiB,CAAC,EAAE,CAClB,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,EAC7B,WAAW,EAAE;QACX,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,WAAW,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;QACjE,cAAc,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,GAAG,SAAS,KAAK,IAAI,CAAC;QACpE,eAAe,EAAE,MAAM,CAAC;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC7B,KACE,KAAK,CAAC,SAAS,CAAC;IAErB,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,KAAK,CAAC,SAAS,CAAC;CACjE,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,eAAe,EACf,QAAQ,EACR,KAAK,EACL,KAAU,EACV,kBAAkB,EAClB,iBAAiB,EACjB,UAAU,GACX,EAAE,KAAK,2CAmDP"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState, useEffect } from "react";
|
|
4
|
+
import { CONSTANTS } from "sea-platform-helpers";
|
|
5
|
+
import { getCookie } from "../../utils/cookie";
|
|
6
|
+
import { jwtDecode } from "../../utils/jwt";
|
|
7
|
+
import CommentForm from "./comment-form";
|
|
8
|
+
import CommentsList from "./comments-list";
|
|
9
|
+
import CommentItem from "./comment-item";
|
|
10
|
+
export default function CommentsContainer({ commentsBaseUrl, objectId, model, limit = 10, highlightCommentId, renderCommentItem, renderForm, }) {
|
|
11
|
+
const [accountId, setAccountId] = useState("");
|
|
12
|
+
const [commentToEdit, setCommentToEdit] = useState();
|
|
13
|
+
const [replyOnComment, setReplyOnComment] = useState();
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
const accessToken = (_a = getCookie(CONSTANTS.JWT.JWTCookieKey)) !== null && _a !== void 0 ? _a : "";
|
|
17
|
+
const payload = (_b = jwtDecode(accessToken)) !== null && _b !== void 0 ? _b : null;
|
|
18
|
+
setAccountId((payload === null || payload === void 0 ? void 0 : payload.id) || "");
|
|
19
|
+
}, []);
|
|
20
|
+
return (_jsxs("div", { className: "flex flex-col gap-2", children: [_jsx(CommentForm, { commentsBaseUrl: commentsBaseUrl, objectId: objectId, model: model, commentToEdit: commentToEdit, setCommentToEdit: setCommentToEdit, replyOnComment: replyOnComment, setReplyOnComment: setReplyOnComment, onCreateCommentSuccess: () => {
|
|
21
|
+
setCommentToEdit(undefined);
|
|
22
|
+
setReplyOnComment(undefined);
|
|
23
|
+
}, onEditCommentSuccess: () => {
|
|
24
|
+
setCommentToEdit(undefined);
|
|
25
|
+
setReplyOnComment(undefined);
|
|
26
|
+
}, renderForm: renderForm }), _jsx(CommentsList, { editComment: setCommentToEdit, replyOnComment: setReplyOnComment, highlightCommentId: highlightCommentId, currentAccountId: accountId, commentsBaseUrl: commentsBaseUrl, objectId: objectId, limit: limit, renderCommentItem: renderCommentItem !== null && renderCommentItem !== void 0 ? renderCommentItem : ((comment, props) => (_jsx(CommentItem, { comment: comment, ...props }, comment.id))) })] }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DTO } from "sea-platform-helpers";
|
|
2
|
+
export declare function useComments({ commentsBaseUrl, objectId, limit, parentCommentId, }: {
|
|
3
|
+
commentsBaseUrl: string;
|
|
4
|
+
objectId: string;
|
|
5
|
+
limit?: number;
|
|
6
|
+
parentCommentId?: string;
|
|
7
|
+
}): {
|
|
8
|
+
comments: DTO.Comment.IComment[];
|
|
9
|
+
loading: boolean;
|
|
10
|
+
totalCount: number;
|
|
11
|
+
totalPages: number;
|
|
12
|
+
pushNewComment: (comment: DTO.Comment.IComment) => void;
|
|
13
|
+
updateComment: (comment: DTO.Comment.IComment) => void;
|
|
14
|
+
loadMoreComments: () => void;
|
|
15
|
+
hasMoreComments: boolean;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/comments-container copy/use-comments/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,GAAG,EAAS,MAAM,sBAAsB,CAAC;AAGlD,wBAAgB,WAAW,CAAC,EAC1B,eAAe,EACf,QAAQ,EACR,KAAU,EACV,eAAe,GAChB,EAAE;IACD,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;;;;;8BA0CkC,GAAG,CAAC,OAAO,CAAC,QAAQ;6BAkBrB,GAAG,CAAC,OAAO,CAAC,QAAQ;;;EAkBrD"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import { Utils } from "sea-platform-helpers";
|
|
4
|
+
import { authAxiosInstance } from "../../../utils/auth-axios";
|
|
5
|
+
export function useComments({ commentsBaseUrl, objectId, limit = 10, parentCommentId, }) {
|
|
6
|
+
const [loading, setLoading] = useState(false);
|
|
7
|
+
const [page, setPage] = useState(1);
|
|
8
|
+
const [totalCount, setTotalCount] = useState(0);
|
|
9
|
+
const [totalPages, setTotalPages] = useState(1);
|
|
10
|
+
const [comments, setComments] = useState([]);
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
setLoading(true);
|
|
13
|
+
const params = new URLSearchParams({
|
|
14
|
+
page: String(page),
|
|
15
|
+
limit: String(limit),
|
|
16
|
+
objectId,
|
|
17
|
+
...(parentCommentId ? { parentCommentId } : {}),
|
|
18
|
+
});
|
|
19
|
+
authAxiosInstance
|
|
20
|
+
.get(`${commentsBaseUrl}?${params.toString()}`)
|
|
21
|
+
.then((response) => {
|
|
22
|
+
const { data, totalCount: tc, totalPages: tp } = response.data;
|
|
23
|
+
setTotalCount(tc);
|
|
24
|
+
setTotalPages(tp);
|
|
25
|
+
setComments((prev) => Utils.Array.concatWithoutDuplicates(prev, data, (a, b) => a.id === b.id));
|
|
26
|
+
})
|
|
27
|
+
.finally(() => {
|
|
28
|
+
setLoading(false);
|
|
29
|
+
});
|
|
30
|
+
}, [commentsBaseUrl, limit, objectId, page]);
|
|
31
|
+
const pushNewComment = (comment) => {
|
|
32
|
+
setComments((prev) => {
|
|
33
|
+
if (comment.isReply && !parentCommentId) {
|
|
34
|
+
return prev.map((c) => c.id === comment.parentCommentId
|
|
35
|
+
? { ...c, repliesCount: c.repliesCount + 1 }
|
|
36
|
+
: c);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
return Utils.Array.concatWithoutDuplicates([comment], prev, (a, b) => a.id === b.id);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
const updateComment = (comment) => {
|
|
44
|
+
setComments((prev) => prev.map((c) => (c.id === comment.id ? comment : c)));
|
|
45
|
+
};
|
|
46
|
+
const loadMoreComments = () => {
|
|
47
|
+
setPage((prev) => Math.min(prev + 1, totalPages));
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
comments,
|
|
51
|
+
loading,
|
|
52
|
+
totalCount,
|
|
53
|
+
totalPages,
|
|
54
|
+
pushNewComment,
|
|
55
|
+
updateComment,
|
|
56
|
+
loadMoreComments,
|
|
57
|
+
hasMoreComments: totalCount !== comments.length,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { FormikProps, FormikHelpers } from "formik";
|
|
2
|
+
export type Props<T, K> = {
|
|
3
|
+
name: string;
|
|
4
|
+
initialValues?: Partial<T>;
|
|
5
|
+
objectToEdit?: {
|
|
6
|
+
id: string;
|
|
7
|
+
} & K;
|
|
8
|
+
mapEditToInitial?: (item: K) => Partial<T>;
|
|
9
|
+
validationSchema?: any;
|
|
10
|
+
onCreate: (values: T, helpers: FormikHelpers<T>) => Promise<K>;
|
|
11
|
+
onUpdate?: (id: string, values: T, helpers: FormikHelpers<T>) => Promise<K>;
|
|
12
|
+
children: (formik: FormikProps<T>, objectToEdit: K) => React.ReactNode;
|
|
6
13
|
};
|
|
7
|
-
export default function Form<T, K,
|
|
8
|
-
export {};
|
|
14
|
+
export default function Form<T, K>({ name, initialValues, objectToEdit, mapEditToInitial, validationSchema, onCreate, onUpdate, children, }: Props<T, K>): import("react/jsx-runtime").JSX.Element;
|
|
9
15
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/form/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/form/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,WAAW,EACX,aAAa,EAGd,MAAM,QAAQ,CAAC;AAGhB,MAAM,MAAM,KAAK,CAAC,CAAC,EAAE,CAAC,IAAI;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3B,YAAY,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAA;KAAE,GAAG,CAAC,CAAC;IAClC,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAE3C,gBAAgB,CAAC,EAAE,GAAG,CAAC;IACvB,QAAQ,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC/D,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5E,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;CACxE,CAAC;AA+CF,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EACjC,IAAI,EACJ,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,gBAAgB,EAChB,QAAQ,EACR,QAAQ,EACR,QAAQ,GACT,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,2CAiDb"}
|