diff --git a/web/components/core/sidebar/links-list.tsx b/web/components/core/sidebar/links-list.tsx index afa28375f..bd4e1af68 100644 --- a/web/components/core/sidebar/links-list.tsx +++ b/web/components/core/sidebar/links-list.tsx @@ -7,107 +7,111 @@ import { Tooltip, TOAST_TYPE, setToast } from "@plane/ui"; // helpers import { calculateTimeAgo } from "@/helpers/date-time.helper"; // hooks -import { useMember } from "@/hooks/store"; +import { useMember, useModule } from "@/hooks/store"; import { usePlatformOS } from "@/hooks/use-platform-os"; // types type Props = { - links: ILinkDetails[]; + moduleId: string; + handleDeleteLink: (linkId: string) => void; handleEditLink: (link: ILinkDetails) => void; userAuth: UserAuth; disabled?: boolean; }; -export const LinksList: React.FC = observer( - ({ links, handleDeleteLink, handleEditLink, userAuth, disabled }) => { - const { getUserDetails } = useMember(); - const { isMobile } = usePlatformOS(); - const isNotAllowed = userAuth.isGuest || userAuth.isViewer || disabled; +export const LinksList: React.FC = observer((props) => { + const { moduleId, handleDeleteLink, handleEditLink, userAuth, disabled } = props; + // hooks + const { getUserDetails } = useMember(); + const { isMobile } = usePlatformOS(); + const { getModuleById } = useModule(); + // derived values + const currentModule = getModuleById(moduleId); + const moduleLinks = currentModule?.link_module || undefined; + const isNotAllowed = userAuth.isGuest || userAuth.isViewer || disabled; - const copyToClipboard = (text: string) => { - navigator.clipboard.writeText(text); - setToast({ - type: TOAST_TYPE.SUCCESS, - title: "Copied to clipboard", - message: "The URL has been successfully copied to your clipboard", - }); - }; + const copyToClipboard = (text: string) => { + navigator.clipboard.writeText(text); + setToast({ + type: TOAST_TYPE.SUCCESS, + title: "Copied to clipboard", + message: "The URL has been successfully copied to your clipboard", + }); + }; - return ( - <> - {links.map((link) => { - const createdByDetails = getUserDetails(link.created_by); - return ( -
-
-
- - + if (!moduleLinks) return <>; + return ( + <> + {moduleLinks.map((link) => { + const createdByDetails = getUserDetails(link.created_by); + return ( +
+
+
+ + + + + copyToClipboard(link.title && link.title !== "" ? link.title : link.url)} + > + {link.title && link.title !== "" ? link.title : link.url} - - copyToClipboard(link.title && link.title !== "" ? link.title : link.url)} - > - {link.title && link.title !== "" ? link.title : link.url} - - -
+ +
- {!isNotAllowed && ( -
- - - - - -
- )} -
-
-

- Added {calculateTimeAgo(link.created_at)} -
- {createdByDetails && ( - <> - by{" "} - {createdByDetails?.is_bot - ? createdByDetails?.first_name + " Bot" - : createdByDetails?.display_name} - - )} -

-
+ {!isNotAllowed && ( +
+ + + + + +
+ )}
- ); - })} - - ); - } -); +
+

+ Added {calculateTimeAgo(link.created_at)} +
+ {createdByDetails && ( + <> + by{" "} + {createdByDetails?.is_bot ? createdByDetails?.first_name + " Bot" : createdByDetails?.display_name} + + )} +

+
+
+ ); + })} + + ); +}); diff --git a/web/components/modules/sidebar.tsx b/web/components/modules/sidebar.tsx index a4585956e..6da125286 100644 --- a/web/components/modules/sidebar.tsx +++ b/web/components/modules/sidebar.tsx @@ -673,18 +673,20 @@ export const ModuleDetailsSidebar: React.FC = observer((props) => {
)} - + {moduleId && ( + + )} ) : (
diff --git a/web/store/module.store.ts b/web/store/module.store.ts index 01ba2c4b0..f591c5df2 100644 --- a/web/store/module.store.ts +++ b/web/store/module.store.ts @@ -1,3 +1,4 @@ +import concat from "lodash/concat"; import set from "lodash/set"; import sortBy from "lodash/sortBy"; import update from "lodash/update"; @@ -372,13 +373,22 @@ export class ModulesStore implements IModuleStore { * @param data * @returns ILinkDetails */ - createModuleLink = async (workspaceSlug: string, projectId: string, moduleId: string, data: Partial) => - await this.moduleService.createModuleLink(workspaceSlug, projectId, moduleId, data).then((response) => { + createModuleLink = async ( + workspaceSlug: string, + projectId: string, + moduleId: string, + data: Partial + ) => { + try { + const moduleLink = await this.moduleService.createModuleLink(workspaceSlug, projectId, moduleId, data); runInAction(() => { - set(this.moduleMap, [moduleId, "link_module"], [response]); + update(this.moduleMap, [moduleId, "link_module"], (moduleLinks = []) => concat(moduleLinks, moduleLink)); }); - return response; - }); + return moduleLink; + } catch (error) { + throw error; + } + }; /** * @description updates module link details @@ -422,14 +432,19 @@ export class ModulesStore implements IModuleStore { * @param moduleId * @param linkId */ - deleteModuleLink = async (workspaceSlug: string, projectId: string, moduleId: string, linkId: string) => - await this.moduleService.deleteModuleLink(workspaceSlug, projectId, moduleId, linkId).then(() => { - const moduleDetails = this.getModuleById(moduleId); - const linkModules = moduleDetails?.link_module?.filter((link) => link.id !== linkId); + deleteModuleLink = async (workspaceSlug: string, projectId: string, moduleId: string, linkId: string) => { + try { + const moduleLink = await this.moduleService.deleteModuleLink(workspaceSlug, projectId, moduleId, linkId); runInAction(() => { - set(this.moduleMap, [moduleId, "link_module"], linkModules); + update(this.moduleMap, [moduleId, "link_module"], (moduleLinks = []) => + moduleLinks.filter((link: ILinkDetails) => link.id !== linkId) + ); }); - }); + return moduleLink; + } catch (error) { + throw error; + } + }; /** * @description adds a module to favorites