Skip to content

Commit 08e86f0

Browse files
fix: selected user ids interfaces on experience (#1780)
* fix: updated selected user id interfaces on timeline * fear: added new option friend only visibility on create experience
1 parent de866c2 commit 08e86f0

8 files changed

Lines changed: 44 additions & 17 deletions

File tree

pages/experience/[experienceId]/clone.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ export const getServerSideProps = wrapper.getServerSideProps(
111111

112112
if (experience?.visibility === 'selected_user') {
113113
const user = (await dispatch(fetchUser())) as unknown as User;
114-
if (
115-
!experience?.selectedUserIds?.includes(user?.id) &&
116-
experience?.createdBy !== user?.id
117-
)
114+
const found = experience?.selectedUserIds?.find(
115+
e => e.userId === user?.id,
116+
);
117+
if (!found && experience?.createdBy !== user?.id)
118118
return {
119119
notFound: true,
120120
};

pages/experience/[experienceId]/index.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,10 @@ export const getServerSideProps = wrapper.getServerSideProps(
147147
if (anonymous) hidden = true;
148148

149149
const user = (await dispatch(fetchUser())) as unknown as User;
150-
if (
151-
!experience?.selectedUserIds?.includes(user?.id) &&
152-
experience?.createdBy !== user?.id
153-
)
154-
hidden = true;
150+
const found = experience?.selectedUserIds?.find(
151+
e => e.userId === user?.id,
152+
);
153+
if (!found && experience?.createdBy !== user?.id) hidden = true;
155154
}
156155

157156
if (experience?.visibility === 'private') {

src/components/ExperienceEditor/ExperienceEditor.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
ExperienceProps,
3434
VisibilityItem,
3535
Tag,
36+
SelectedUserIds,
3637
} from '../../interfaces/experience';
3738
import { People } from '../../interfaces/people';
3839
import { PostDetailExperience } from '../PostDetailExperience/PostDetailExperience';
@@ -408,6 +409,10 @@ export const ExperienceEditor: React.FC<ExperienceEditorProps> = props => {
408409
id: 'selected_user',
409410
name: i18n.t('Experience.Editor.Visibility.Custom'),
410411
},
412+
{
413+
id: 'friend',
414+
name: i18n.t('Experience.Editor.Visibility.Friend_Only'),
415+
},
411416
];
412417

413418
const handleVisibilityChange = (
@@ -474,7 +479,15 @@ export const ExperienceEditor: React.FC<ExperienceEditorProps> = props => {
474479
const mappingUserIds = () => {
475480
console.log({ selectedVisibility });
476481
if (selectedVisibility?.id === 'selected_user') {
477-
const mapIds = Object.values(selectedUserIds.map(option => option.id));
482+
const timestamp = Date.now();
483+
const mapIds = Object.values(
484+
selectedUserIds.map(option => {
485+
return {
486+
userId: option.id,
487+
addedAt: timestamp,
488+
};
489+
}),
490+
);
478491
setNewExperience(prevExperience => ({
479492
...prevExperience,
480493
selectedUserIds: mapIds,
@@ -493,8 +506,9 @@ export const ExperienceEditor: React.FC<ExperienceEditorProps> = props => {
493506
// eslint-disable-next-line react-hooks/exhaustive-deps
494507
}, [selectedUserIds, experience]);
495508

496-
const getSelectedIds = async (userIds: string[]) => {
509+
const getSelectedIds = async (selected: SelectedUserIds[]) => {
497510
setIsLoadingSelectedUser(true);
511+
const userIds = selected.map(e => e.userId);
498512
const response = await UserAPI.getUserByIds(userIds, pageUserIds);
499513
setSelectedUserIds([
500514
...selectedUserIds,
@@ -508,6 +522,7 @@ export const ExperienceEditor: React.FC<ExperienceEditorProps> = props => {
508522
React.useEffect(() => {
509523
getSelectedIds(experience?.selectedUserIds);
510524
}, [experience, pageUserIds]);
525+
511526
useEffect(() => {
512527
if (experience) {
513528
const visibility = visibilityList.find(

src/components/ExperiencePreview/ExperiencePreview.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ import ShowIf from 'components/common/show-if.component';
2323
import { ListItemPeopleComponent } from 'src/components/atoms/ListItem/ListItemPeople';
2424
import { acronym } from 'src/helpers/string';
2525
import { useExperienceHook } from 'src/hooks/use-experience-hook';
26-
import { Experience, WrappedExperience } from 'src/interfaces/experience';
26+
import {
27+
Experience,
28+
SelectedUserIds,
29+
WrappedExperience,
30+
} from 'src/interfaces/experience';
2731
import { People } from 'src/interfaces/people';
2832
import { SocialsEnum } from 'src/interfaces/social';
2933
import { User } from 'src/interfaces/user';
@@ -205,8 +209,9 @@ export const ExperiencePreview: React.FC<Props> = props => {
205209
return i18n.t('Experience.Editor.Visibility.Custom');
206210
};
207211

208-
const getSelectedIds = async (userIds: string[]) => {
212+
const getSelectedIds = async (selected: SelectedUserIds[]) => {
209213
setIsLoadingSelectedUser(true);
214+
const userIds = selected.map(e => e.userId);
210215
const response = await UserAPI.getUserByIds(userIds, pageUserIds);
211216
setSelectedUserIds([
212217
...selectedUserIds,

src/interfaces/experience.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export type TagProps = {
1515
hide?: boolean;
1616
};
1717

18+
export interface SelectedUserIds {
19+
userId: string;
20+
addedAt: number;
21+
}
22+
1823
export interface Tag extends TagProps, Omit<BaseModel, 'id'> {}
1924

2025
export interface Topic extends Searchable {
@@ -37,7 +42,7 @@ export interface ExperienceProps extends Searchable {
3742
prohibitedTags?: string[];
3843
people: People[];
3944
visibility: string;
40-
selectedUserIds: string[];
45+
selectedUserIds: SelectedUserIds[];
4146
}
4247

4348
export interface Experience extends ExperienceProps, BaseModel {

src/locale/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@
121121
"Visibility": {
122122
"Public": "Public",
123123
"OnlyMe": "Only Me",
124-
"Custom": "Custom"
124+
"Custom": "Custom",
125+
"Friend_Only": "Friend Only"
125126
}
126127
},
127128
"Modal_Add_Post": {

src/locale/id.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@
121121
"Visibility": {
122122
"Public": "Publik",
123123
"OnlyMe": "Hanya Saya",
124-
"Custom": "Kustom"
124+
"Custom": "Kustom",
125+
"Friend_Only": "Hanya teman"
125126
}
126127
},
127128
"Modal_Add_Post": {

src/locale/ru.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@
121121
"Visibility": {
122122
"Public": "Общественный",
123123
"OnlyMe": "Только я",
124-
"Custom": "Обычай"
124+
"Custom": "Обычай",
125+
"Friend_Only": "Только друзья"
125126
}
126127
},
127128
"Modal_Add_Post": {

0 commit comments

Comments
 (0)