diff --git a/src/components/announcements/TcAnnouncementsTable.tsx b/src/components/announcements/TcAnnouncementsTable.tsx index aed0614d..df28b871 100644 --- a/src/components/announcements/TcAnnouncementsTable.tsx +++ b/src/components/announcements/TcAnnouncementsTable.tsx @@ -143,13 +143,18 @@ function TcAnnouncementsTable({ style={{ height: '8px', width: '8px', - background: announcement.draft ? '#3A9E2B' : '#FF9022', + background: !announcement.draft ? '#3A9E2B' : '#FF9022', borderRadius: '50%', display: 'inline-block', marginRight: '5px', }} /> - {truncateCenter(announcement.data[0].template, 20)} + {announcement && + announcement.data && + announcement.data[0] && + announcement.data[0].template + ? truncateCenter(announcement.data[0]?.template, 20) + : ''} } variant="subtitle2" @@ -318,55 +323,66 @@ function TcAnnouncementsTable({ const renderTableBody = () => { if (isLoading) { return ( - - - - - - ); - } - - return announcements.map((announcement, index) => ( - - {['title', 'channels', 'users', 'roles', 'scheduledAt', 'actions'].map( - (cellType, cellIndex, array) => ( + + - {renderTableCell(announcement, cellType)} + - ) - )} - - )); + + + ); + } + + return ( + + {announcements.map((announcement, index) => ( + + {[ + 'title', + 'channels', + 'users', + 'roles', + 'scheduledAt', + 'actions', + ].map((cellType, cellIndex, array) => ( + + {renderTableCell(announcement, cellType)} + + ))} + + ))} + + ); }; return ( @@ -452,7 +468,7 @@ function TcAnnouncementsTable({ > - {renderTableBody()} + {renderTableBody()} ([]); const [fetchedRoles, setFetchedRoles] = useState({ - limit: 8, + limit: 100, page: 1, results: [], totalPages: 0, @@ -92,16 +92,16 @@ function TcRolesAutoComplete({ if (inputValue === '') { setFilteredRolesByName(''); setFetchedRoles({ - limit: 8, + limit: 100, page: 1, results: [], totalPages: 0, totalResults: 0, }); - debouncedFetchDiscordRoles(platformId, 1, 8); + debouncedFetchDiscordRoles(platformId, 1, 100); } else { - debouncedFetchDiscordRoles(platformId, 1, 8, inputValue); + debouncedFetchDiscordRoles(platformId, 1, 100, inputValue); } }; @@ -153,7 +153,13 @@ function TcRolesAutoComplete({ value={selectedRoles} onChange={handleChange} onInputChange={handleSearchChange} + isOptionEqualToValue={(option, value) => option.roleId === value.roleId} disableCloseOnSelect + renderOption={(props, option) => ( +
  • + {option.name} +
  • + )} renderTags={(value, getTagProps) => value.map((option, index) => ( ([]); const [fetchedUsers, setFetchedUsers] = useState({ - limit: 8, + limit: 100, page: 1, results: [], totalPages: 0, totalResults: 0, }); - const [filteredRolesByName, setFilteredRolesByName] = useState(''); + const [filteredUsersByName, setFilteredUsersByName] = useState(''); const [isInitialized, setIsInitialized] = useState(false); const fetchDiscordUsers = async ( @@ -54,7 +54,7 @@ function TcUsersAutoComplete({ }); if (ngu) { - setFilteredRolesByName(ngu); + setFilteredUsersByName(ngu); setFetchedUsers(fetchedUsers); } else { setFetchedUsers((prevData: { results: any }) => { @@ -90,18 +90,18 @@ function TcUsersAutoComplete({ if (!platformId) return; if (inputValue === '') { - setFilteredRolesByName(''); + setFilteredUsersByName(''); setFetchedUsers({ - limit: 8, + limit: 100, page: 1, results: [], totalPages: 0, totalResults: 0, }); - debouncedFetchDiscordUsers(platformId, 1, 8); + debouncedFetchDiscordUsers(platformId, 1, 100); } else { - debouncedFetchDiscordUsers(platformId, 1, 8, inputValue); + debouncedFetchDiscordUsers(platformId, 1, 100, inputValue); } }; @@ -153,7 +153,15 @@ function TcUsersAutoComplete({ value={selectedUsers} onChange={handleChange} onInputChange={handleSearchChange} + isOptionEqualToValue={(option, value) => + option.discordId === value.discordId + } disableCloseOnSelect + renderOption={(props, option) => ( +
  • + {option.ngu} +
  • + )} renderTags={(value, getTagProps) => value.map((option, index) => ( { - if (isEdit) { + if (isEdit && preSelectedTime) { const date = moment(preSelectedTime); + setSelectedDate(date.toDate()); setSelectedTime(date.toDate()); setDateTimeDisplay(date.format('D MMMM YYYY @ h A')); } - }, [isEdit]); + }, [isEdit, preSelectedTime]); return (
    diff --git a/src/components/pages/pageIndex/HeatmapChart.tsx b/src/components/pages/pageIndex/HeatmapChart.tsx index 526075d2..d578ea17 100644 --- a/src/components/pages/pageIndex/HeatmapChart.tsx +++ b/src/components/pages/pageIndex/HeatmapChart.tsx @@ -58,8 +58,6 @@ const HeatmapChart = () => { const fetchData = async () => { setLoading(true); try { - console.log({ selectedSubChannels }); - if (platformId) { const data = await fetchHeatmapData( platformId, diff --git a/src/pages/announcements/edit-announcements/index.tsx b/src/pages/announcements/edit-announcements/index.tsx index e67287d4..ee475759 100644 --- a/src/pages/announcements/edit-announcements/index.tsx +++ b/src/pages/announcements/edit-announcements/index.tsx @@ -113,7 +113,6 @@ function Index() { (channel) => channel.channelId ); } - console.log({ channelIds }); await refreshData(platformId, 'channel', channelIds, undefined, false); } @@ -127,7 +126,9 @@ function Index() { if (!id) return; const fetchAnnouncement = async () => { const data = await retrieveAnnouncementById(id); + setFetchedAnnouncements(data); + setScheduledAt(data.scheduledAt); }; fetchAnnouncement(); @@ -155,9 +156,10 @@ function Index() { try { setLoading(true); const data = await patchExistingAnnouncement(id, announcementsPayload); + if (data) { showMessage('Announcement updated successfully', 'success'); - router.push('/announcements'); + location.replace('/announcements'); } } catch (error) { showMessage('Failed to create announcement', 'error'); diff --git a/src/store/slices/announcementsSlice.ts b/src/store/slices/announcementsSlice.ts index 1d2a06fb..984afcd4 100644 --- a/src/store/slices/announcementsSlice.ts +++ b/src/store/slices/announcementsSlice.ts @@ -10,7 +10,6 @@ const createAnnouncementsSlice: StateCreator = (set, get) => ({ page, limit, sortBy, - ngu, timeZone, startDate, endDate, @@ -24,7 +23,6 @@ const createAnnouncementsSlice: StateCreator = (set, get) => ({ ...(timeZone ? { timeZone } : {}), ...(startDate ? { startDate } : {}), ...(endDate ? { endDate } : {}), - ...(ngu ? { name } : {}), }; const { data } = await axiosInstance.get( @@ -63,8 +61,6 @@ const createAnnouncementsSlice: StateCreator = (set, get) => ({ announcementPayload: CreateAnnouncementsPayload ) => { try { - console.log({ id }); - const { data } = await axiosInstance.patch( `/announcements/${id}`, announcementPayload diff --git a/src/store/slices/platformSlice.ts b/src/store/slices/platformSlice.ts index 243096e1..8bee293b 100644 --- a/src/store/slices/platformSlice.ts +++ b/src/store/slices/platformSlice.ts @@ -72,6 +72,7 @@ const createPlatfromSlice: StateCreator = (set, get) => ({ platformId, property = 'channel', name, + ngu, sortBy, page, limit, @@ -89,6 +90,8 @@ const createPlatfromSlice: StateCreator = (set, get) => ({ if (name) params.append('name', name); + if (ngu) params.append('ngu', ngu); + if (page !== undefined) { params.append('page', page.toString()); } diff --git a/src/store/types/IAnnouncements.ts b/src/store/types/IAnnouncements.ts index 37937eac..672897f2 100644 --- a/src/store/types/IAnnouncements.ts +++ b/src/store/types/IAnnouncements.ts @@ -2,7 +2,6 @@ export interface IRetrieveAnnouncementsProps { page: number; limit: number; sortBy?: string; - ngu?: string; community: string; startDate?: string; endDate?: string; @@ -14,7 +13,6 @@ export default interface IAnnouncements { page, limit, sortBy, - ngu, community, }: IRetrieveAnnouncementsProps) => void; } diff --git a/src/store/types/IPlatform.ts b/src/store/types/IPlatform.ts index f88e42ca..16c7574d 100644 --- a/src/store/types/IPlatform.ts +++ b/src/store/types/IPlatform.ts @@ -13,6 +13,7 @@ export interface IRetrivePlatformRolesOrChannels { limit?: number; sortBy?: string; name?: string; + ngu?: string; platformId: string; property: 'channel' | 'role' | 'guildMember'; }