Skip to content

Commit

Permalink
Merge pull request #246 from TogetherCrew/feat/announcements-payload-…
Browse files Browse the repository at this point in the history
…change

update payload for privateMessage
  • Loading branch information
mehdi-torabiv authored Feb 5, 2024
2 parents 41d993c + a37d154 commit 6e9996e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 51 deletions.
48 changes: 23 additions & 25 deletions src/pages/announcements/create-new-announcements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,48 +160,46 @@ function CreateNewAnnouncements() {
}) => {
if (!platformId) return;

let rolePrivateAnnouncements;
let userPrivateAnnouncements;

const commonData = {
platformId: platformId,
template: message,
};

let privateAnnouncementsOptions: {
roleIds: string[];
userIds: string[];
} = {
roleIds: [],
userIds: [],
};

if (selectedRoles && selectedRoles.length > 0) {
setRoles(selectedRoles);

rolePrivateAnnouncements = {
...commonData,
options: {
roleIds: selectedRoles.map((role) =>
role.roleId.toString()
),
},
};
privateAnnouncementsOptions.roleIds = selectedRoles.map(
(role) => role.roleId.toString()
);
}

if (selectedUsers && selectedUsers.length > 0) {
setUsers(selectedUsers);
privateAnnouncementsOptions.userIds = selectedUsers.map(
(user) => user.discordId
);
}

userPrivateAnnouncements = {
if (
privateAnnouncementsOptions.roleIds.length > 0 ||
privateAnnouncementsOptions.userIds.length > 0
) {
const combinedPrivateAnnouncement = {
...commonData,
options: {
userIds: selectedUsers.map((user) => user.discordId),
},
options: privateAnnouncementsOptions,
};
}

const announcements = [];
if (rolePrivateAnnouncements)
announcements.push(rolePrivateAnnouncements);
if (userPrivateAnnouncements)
announcements.push(userPrivateAnnouncements);

setPrivateAnnouncements(announcements);
setPrivateAnnouncements([combinedPrivateAnnouncement]);
}
}}
/>

<TcScheduleAnnouncement
handleSchaduledDate={({ selectedTime }) => {
setScheduledAt(selectedTime);
Expand Down
51 changes: 25 additions & 26 deletions src/pages/announcements/edit-announcements/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useContext, useEffect, useMemo, useState } from 'react';
import { defaultLayout } from '../../../layouts/defaultLayout';
import SEO from '../../../components/global/SEO';
import { useRouter } from 'next/router';
import TcPrivateMessaageContainer from '../../../components/announcements/create/privateMessaageContainer';
import TcPrivateMessageContainer from '../../../components/announcements/create/privateMessaageContainer';
import TcPublicMessaageContainer from '../../../components/announcements/create/publicMessageContainer';
import TcScheduleAnnouncement from '../../../components/announcements/create/scheduleAnnouncement';
import TcSelectPlatform from '../../../components/announcements/create/selectPlatform';
Expand Down Expand Up @@ -207,7 +207,7 @@ function Index() {
});
}}
/>
<TcPrivateMessaageContainer
<TcPrivateMessageContainer
isEdit={true}
privateAnnouncementsData={privateSelectedAnnouncements}
handlePrivateAnnouncements={({
Expand All @@ -217,45 +217,44 @@ function Index() {
}) => {
if (!platformId) return;

let rolePrivateAnnouncements;
let userPrivateAnnouncements;

const commonData = {
platformId: platformId,
template: message,
};

let privateAnnouncementsOptions: {
roleIds: string[];
userIds: string[];
} = {
roleIds: [],
userIds: [],
};

if (selectedRoles && selectedRoles.length > 0) {
setRoles(selectedRoles);

rolePrivateAnnouncements = {
...commonData,
options: {
roleIds: selectedRoles.map((role) =>
role.roleId.toString()
),
},
};
privateAnnouncementsOptions.roleIds = selectedRoles.map(
(role) => role.roleId.toString()
);
}

if (selectedUsers && selectedUsers.length > 0) {
setUsers(selectedUsers);
privateAnnouncementsOptions.userIds = selectedUsers.map(
(user) => user.discordId
);
}

userPrivateAnnouncements = {
if (
privateAnnouncementsOptions.roleIds.length > 0 ||
privateAnnouncementsOptions.userIds.length > 0
) {
const combinedPrivateAnnouncement = {
...commonData,
options: {
userIds: selectedUsers.map((user) => user.discordId),
},
options: privateAnnouncementsOptions,
};
}

const announcements = [];
if (rolePrivateAnnouncements)
announcements.push(rolePrivateAnnouncements);
if (userPrivateAnnouncements)
announcements.push(userPrivateAnnouncements);

setPrivateAnnouncements(announcements);
setPrivateAnnouncements([combinedPrivateAnnouncement]);
}
}}
/>
<TcScheduleAnnouncement
Expand Down

0 comments on commit 6e9996e

Please sign in to comment.