-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b34455c
commit 90f8324
Showing
8 changed files
with
147 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...dvancedSettings/components/ConfirmationModal/components/ChangeItem/ChangeItem.module.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
@import "../../../../../../../../../constants"; | ||
|
||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
} | ||
|
||
.title { | ||
margin-bottom: 0.5rem; | ||
font-weight: bold; | ||
} | ||
|
||
.text { | ||
margin-bottom: 0.5rem; | ||
|
||
&:last-child { | ||
margin-bottom: 0; | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...Formik/AdvancedSettings/components/ConfirmationModal/components/ChangeItem/ChangeItem.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { FC } from "react"; | ||
import { CommonCircleChange } from "../../types"; | ||
import styles from "./ChangeItem.module.scss"; | ||
|
||
interface ChangeItemProps { | ||
change: CommonCircleChange; | ||
} | ||
|
||
const ChangeItem: FC<ChangeItemProps> = (props) => { | ||
const { change } = props; | ||
|
||
return ( | ||
<li className={styles.container}> | ||
<span className={styles.title}>{change.commonName}</span> | ||
{change.removedUsers.length > 0 && ( | ||
<span className={styles.text}> | ||
The following users will be removed from {change.commonName}:{" "} | ||
{change.removedUsers.map(({ userName }) => userName).join(", ")} | ||
</span> | ||
)} | ||
{change.changes.map( | ||
({ circleId, circleName, addedUsers, removedUsers }) => ( | ||
<React.Fragment key={circleId}> | ||
{addedUsers.length > 0 && ( | ||
<span className={styles.text}> | ||
The following users will be added to {circleName}:{" "} | ||
{addedUsers.map(({ userName }) => userName).join(", ")} | ||
</span> | ||
)} | ||
{removedUsers.length > 0 && ( | ||
<span className={styles.text}> | ||
The following users will be removed from {circleName}:{" "} | ||
{removedUsers.map(({ userName }) => userName).join(", ")} | ||
</span> | ||
)} | ||
</React.Fragment> | ||
), | ||
)} | ||
</li> | ||
); | ||
}; | ||
|
||
export default ChangeItem; |
1 change: 1 addition & 0 deletions
1
.../Form/Formik/AdvancedSettings/components/ConfirmationModal/components/ChangeItem/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as ChangeItem } from "./ChangeItem"; |
1 change: 1 addition & 0 deletions
1
.../components/Form/Formik/AdvancedSettings/components/ConfirmationModal/components/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./ChangeItem"; |
17 changes: 15 additions & 2 deletions
17
src/shared/components/Form/Formik/AdvancedSettings/components/ConfirmationModal/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,18 @@ | ||
export interface CircleChange { | ||
interface User { | ||
userId: string; | ||
userName: string; | ||
} | ||
|
||
export interface CircleChange { | ||
circleId: string; | ||
circleName: string; | ||
added: boolean; | ||
addedUsers: User[]; | ||
removedUsers: User[]; | ||
} | ||
|
||
export interface CommonCircleChange { | ||
commonId: string; | ||
commonName: string; | ||
removedUsers: User[]; | ||
changes: CircleChange[]; | ||
} |
83 changes: 54 additions & 29 deletions
83
.../Form/Formik/AdvancedSettings/components/ConfirmationModal/utils/generateCircleChanges.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,65 @@ | ||
import { UserService } from "@/services"; | ||
import { PreviewCirclesUpdateResponse } from "@/shared/interfaces"; | ||
import { getUserName } from "@/shared/utils"; | ||
import { CircleChange } from "../types"; | ||
import { CircleChange, CommonCircleChange } from "../types"; | ||
|
||
const getDefaultCircleChange = ( | ||
circleId: string, | ||
circleName: string, | ||
): CircleChange => ({ | ||
circleId, | ||
circleName, | ||
addedUsers: [], | ||
removedUsers: [], | ||
}); | ||
|
||
export const generateCircleChanges = async ({ | ||
changes, | ||
}: PreviewCirclesUpdateResponse): Promise<CircleChange[]> => { | ||
const circleChanges: CircleChange[] = []; | ||
}: PreviewCirclesUpdateResponse): Promise<CommonCircleChange[]> => { | ||
const commonCircleChanges: CommonCircleChange[] = []; | ||
|
||
await Promise.all( | ||
changes.map( | ||
(change) => | ||
Promise.all( | ||
change.members.map(async (member) => { | ||
const user = await UserService.getCachedUserById(member.id); | ||
const userName = getUserName(user) || "Unknown"; | ||
|
||
member.circlesAdded.forEach((addedCircle) => { | ||
circleChanges.push({ | ||
userName, | ||
circleName: addedCircle.name, | ||
added: true, | ||
}); | ||
}); | ||
member.circlesRemoved.forEach((removedCircle) => { | ||
circleChanges.push({ | ||
userName, | ||
circleName: removedCircle.name, | ||
added: false, | ||
}); | ||
}); | ||
}), | ||
), | ||
[], | ||
), | ||
changes.map(async (change) => { | ||
const circleChanges: Record<string, CircleChange> = {}; | ||
const commonCircleChange: CommonCircleChange = { | ||
commonId: change.commonId, | ||
commonName: change.commonName, | ||
removedUsers: [], | ||
changes: [], | ||
}; | ||
|
||
await Promise.all( | ||
change.members.map(async (member) => { | ||
const userId = member.userId; | ||
const user = await UserService.getCachedUserById(userId); | ||
const userName = getUserName(user) || "<Unknown>"; | ||
|
||
if (member.circleIds.length === 0) { | ||
commonCircleChange.removedUsers.push({ userId, userName }); | ||
return; | ||
} | ||
|
||
member.circlesAdded.forEach((addedCircle) => { | ||
const circleChange = | ||
circleChanges[addedCircle.id] || | ||
getDefaultCircleChange(addedCircle.id, addedCircle.name); | ||
circleChange.addedUsers.push({ userId, userName }); | ||
circleChanges[addedCircle.id] = circleChange; | ||
}); | ||
member.circlesRemoved.forEach((removedCircle) => { | ||
const circleChange = | ||
circleChanges[removedCircle.id] || | ||
getDefaultCircleChange(removedCircle.id, removedCircle.name); | ||
circleChange.removedUsers.push({ userId, userName }); | ||
circleChanges[removedCircle.id] = circleChange; | ||
}); | ||
}), | ||
); | ||
|
||
commonCircleChange.changes = Object.values(circleChanges); | ||
commonCircleChanges.push(commonCircleChange); | ||
}), | ||
); | ||
|
||
return circleChanges; | ||
return commonCircleChanges; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters