diff --git a/package-lock.json b/package-lock.json index 11256dda..4c8d3d22 100644 --- a/package-lock.json +++ b/package-lock.json @@ -40,6 +40,7 @@ "highcharts": "^10.3.1", "highcharts-react-official": "^3.1.0", "jwt-decode": "^3.1.2", + "lodash": "^4.17.21", "moment": "^2.29.4", "moment-timezone": "^0.5.38", "next": "13.0.2", @@ -66,6 +67,7 @@ "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.5.1", "@types/d3-force": "^3.0.4", + "@types/lodash": "^4.14.202", "@types/papaparse": "^5.3.8", "@types/testing-library__user-event": "^4.2.0", "autoprefixer": "^10.4.13", @@ -2924,6 +2926,12 @@ "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==" }, + "node_modules/@types/lodash": { + "version": "4.14.202", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.202.tgz", + "integrity": "sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==", + "dev": true + }, "node_modules/@types/node": { "version": "18.11.9", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz", @@ -9053,8 +9061,7 @@ "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "node_modules/lodash-es": { "version": "4.17.21", @@ -13827,6 +13834,12 @@ "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==" }, + "@types/lodash": { + "version": "4.14.202", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.202.tgz", + "integrity": "sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==", + "dev": true + }, "@types/node": { "version": "18.11.9", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.11.9.tgz", @@ -18297,8 +18310,7 @@ "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", - "dev": true + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" }, "lodash-es": { "version": "4.17.21", diff --git a/package.json b/package.json index a1f84fff..85891dc1 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "highcharts": "^10.3.1", "highcharts-react-official": "^3.1.0", "jwt-decode": "^3.1.2", + "lodash": "^4.17.21", "moment": "^2.29.4", "moment-timezone": "^0.5.38", "next": "13.0.2", @@ -70,6 +71,7 @@ "@testing-library/react": "^14.0.0", "@testing-library/user-event": "^14.5.1", "@types/d3-force": "^3.0.4", + "@types/lodash": "^4.14.202", "@types/papaparse": "^5.3.8", "@types/testing-library__user-event": "^4.2.0", "autoprefixer": "^10.4.13", diff --git a/src/components/announcements/create/publicMessageContainer/TcPublicMessageContainer.tsx b/src/components/announcements/create/publicMessageContainer/TcPublicMessageContainer.tsx index 2801d647..fba55ba9 100644 --- a/src/components/announcements/create/publicMessageContainer/TcPublicMessageContainer.tsx +++ b/src/components/announcements/create/publicMessageContainer/TcPublicMessageContainer.tsx @@ -1,9 +1,9 @@ import React, { useContext, useEffect, useState } from 'react'; import TcText from '../../../shared/TcText'; -import { MdAnnouncement, MdExpandMore } from 'react-icons/md'; +import { MdAnnouncement } from 'react-icons/md'; import TcIconContainer from '../TcIconContainer'; import TcSelect from '../../../shared/TcSelect'; -import { FormControl, InputLabel } from '@mui/material'; +import { FormControl, FormHelperText, InputLabel } from '@mui/material'; import TcInput from '../../../shared/TcInput'; import TcPublicMessagePreviewDialog from './TcPublicMessagePreviewDialog'; import { ChannelContext } from '../../../../context/ChannelContext'; @@ -11,7 +11,7 @@ import TcPlatformChannelList from '../../../communitySettings/platform/TcPlatfor import { IGuildChannels } from '../../../../utils/types'; import { DiscordData } from '../../../../pages/announcements/edit-announcements'; import TcPermissionHints from '../../../global/TcPermissionHints'; -import { useToken } from '../../../../context/TokenContext'; +import TcButton from '../../../shared/TcButton'; export interface FlattenedChannel { id: string; @@ -26,7 +26,7 @@ export interface ITcPublicMessageContainerProps { selectedChannels, }: { message: string; - selectedChannels: FlattenedChannel[]; + selectedChannels: FlattenedChannel[] | []; }) => void; } @@ -38,7 +38,9 @@ function TcPublicMessageContainer({ const channelContext = useContext(ChannelContext); const { channels, selectedSubChannels } = channelContext; - const { community } = useToken(); + const [hasInteracted, setHasInteracted] = useState(false); + const [showError, setShowError] = useState(false); + const [isDropdownVisible, setIsDropdownVisible] = useState(false); const flattenChannels = (channels: IGuildChannels[]): FlattenedChannel[] => { let flattened: FlattenedChannel[] = []; @@ -62,6 +64,8 @@ function TcPublicMessageContainer({ const [selectedChannels, setSelectedChannels] = useState( [] ); + const [confirmedSelectedChannels, setConfirmedSelectedChannels] = + useState(false); useEffect(() => { setSelectedChannels(flattenChannels(channels)); @@ -77,8 +81,12 @@ function TcPublicMessageContainer({ selectedChannels.length > 0 && message.length > 0; useEffect(() => { - handlePublicAnnouncements({ message, selectedChannels }); - }, [message, selectedChannels]); + if (confirmedSelectedChannels) { + handlePublicAnnouncements({ message, selectedChannels }); + } else { + handlePublicAnnouncements({ message, selectedChannels: [] }); + } + }, [message, selectedChannels, confirmedSelectedChannels]); useEffect(() => { if (isEdit && publicAnnouncementsData) { @@ -92,13 +100,24 @@ function TcPublicMessageContainer({ label: channel.name, }) ); - + setConfirmedSelectedChannels(true); setSelectedChannels(formattedChannels); setMessage(publicAnnouncementsData.template); } } }, [isEdit, publicAnnouncementsData]); + const handleSaveChannels = () => { + setConfirmedSelectedChannels(true); + setIsDropdownVisible(false); + setShowError(hasInteracted && selectedChannels.length === 0); + }; + + const toggleDropdownVisibility = () => { + setHasInteracted(true); + setIsDropdownVisible(!isDropdownVisible); + }; + return (
@@ -115,14 +134,6 @@ function TcPublicMessageContainer({ />
- {/*
- - -
*/} Select Channels (selected as FlattenedChannel[]) .map((channel) => `#${channel.label}`) @@ -142,8 +155,25 @@ function TcPublicMessageContainer({
+
+ +
+ {showError && ( + + + + )}