Skip to content

Commit

Permalink
feat(uiweb): return response in createGroupModal (#1198)
Browse files Browse the repository at this point in the history
* feat(uiweb): return response in createGroupModal

return group information when group is successfully created in uiweb createGroupModal

* fix: fixed build issue

---------

Co-authored-by: Monalisha Mishra <[email protected]>
Co-authored-by: Monalisha Mishra <[email protected]>
  • Loading branch information
3 people authored Apr 8, 2024
1 parent ae4d055 commit 241080d
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ const AddCriteria = ({
} as DropdownValueType)
}


const onQuantityChange = (e: any) => {
setQuantity({ ...quantity, value: e.target.value });
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,9 @@ import { ProfilePicture, device } from '../../../config';
import { CriteriaValidationErrorType } from '../types';

import { MODAL_BACKGROUND_TYPE, MODAL_POSITION_TYPE } from '../../../types';
import {
CreateGroupModalProps,
IChatTheme,

} from '../exportedTypes';
import { CreateGroupModalProps, IChatTheme } from '../exportedTypes';
import AutoImageClipper from '../reusables/AutoImageClipper';



export const CREATE_GROUP_STEP_KEYS = {
INPUT_DETAILS: 1,
GROUP_TYPE: 2,
Expand All @@ -61,6 +55,7 @@ export const CreateGroupModal: React.FC<CreateGroupModalProps> = ({
onClose,
modalBackground = MODAL_BACKGROUND_TYPE.OVERLAY,
modalPositionType = MODAL_POSITION_TYPE.GLOBAL,
onSuccess,
}) => {
const [activeComponent, setActiveComponent] = useState<CreateGroupStepKeys>(
// replace it with info one
Expand Down Expand Up @@ -107,7 +102,6 @@ export const CreateGroupModal: React.FC<CreateGroupModalProps> = ({
});
const [isImageUploaded, setIsImageUploaded] = useState<boolean>(false);


const showError = (errorMessage: string) => {
groupInfoToast.showMessageToast({
toastTitle: 'Error',
Expand All @@ -118,7 +112,7 @@ export const CreateGroupModal: React.FC<CreateGroupModalProps> = ({
};

const getEncryptionType = () => {
console.debug(groupInputDetails.groupEncryptionType, "encryptionTypeee");
console.debug(groupInputDetails.groupEncryptionType, 'encryptionTypeee');
if (groupInputDetails.groupEncryptionType === 'encrypted') {
return false;
}
Expand All @@ -139,8 +133,10 @@ export const CreateGroupModal: React.FC<CreateGroupModalProps> = ({
.map((member: any) => member.wallets),
};
const rules: any = checked ? criteriaStateManager.generateRule() : {};
const isSuccess = await createGatedGroup(groupInfo, rules);
if (isSuccess === true) {
const { success: isGroupCreated, data: APIResponse } =
await createGatedGroup(groupInfo, rules);
if (isGroupCreated === true) {
onSuccess && onSuccess(APIResponse);
groupInfoToast.showMessageToast({
toastTitle: 'Success',
toastMessage: 'Group created successfully',
Expand Down Expand Up @@ -211,22 +207,23 @@ export const CreateGroupModal: React.FC<CreateGroupModalProps> = ({
onClose={onClose}
/>
);

case CREATE_GROUP_STEP_KEYS.ADD_MEMBERS:
return (
<AddGroupMembers
onSubmit={verifyAndCreateGroup}
onClose={onClose}
handlePrevious={handlePreviousfromAddWallets}
memberList={groupInputDetails.groupMembers}
handleMemberList={(members: any)=>{
setGroupInputDetails(
(prev: GroupInputDetailsType) => ({ ...prev, groupMembers: members})
)}}
handleMemberList={(members: any) => {
setGroupInputDetails((prev: GroupInputDetailsType) => ({
...prev,
groupMembers: members,
}));
}}
isLoading={loading}
isPublic={getEncryptionType()}
/>

);
default:
return (
Expand Down Expand Up @@ -264,7 +261,9 @@ export interface ModalHeaderProps {
handleAddWallets?: () => void;
isImageUploaded?: boolean;
setIsImageUploaded?: React.Dispatch<React.SetStateAction<boolean>>;
setGroupInputDetails?: React.Dispatch<React.SetStateAction<GroupInputDetailsType>>;
setGroupInputDetails?: React.Dispatch<
React.SetStateAction<GroupInputDetailsType>
>;
groupInputDetails?: GroupInputDetailsType;
}

Expand Down Expand Up @@ -494,4 +493,4 @@ const ErrorSpan = styled(Span)`
font-size: 12px;
font-weight: 500;
color: #ed5858;
`;
`;
77 changes: 41 additions & 36 deletions packages/uiweb/src/lib/components/chat/exportedTypes.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import type { CONSTANTS, GroupDTO, GroupInfoDTO, IMessageIPFS } from '@pushprotocol/restapi';
import { IChatTheme } from "./theme";
import { IGroup, ModalBackgroundType, ModalPositionType } from '../../types'

import type {
CONSTANTS,
GroupDTO,
GroupInfoDTO,
IMessageIPFS,
} from '@pushprotocol/restapi';
import { IChatTheme } from './theme';
import { IGroup, ModalBackgroundType, ModalPositionType } from '../../types';

export interface IChatPreviewPayload {
chatId: string | undefined;
Expand All @@ -12,29 +16,34 @@ export interface IChatPreviewPayload {
chatMsg?: {
messageType: string;
messageContent: string | object;
}
};
}

export interface IChatPreviewProps {
chatPreviewPayload: IChatPreviewPayload;
selected?: boolean;
setSelected?: (chatId: string,chatParticipant: string) => void;
setSelected?: (chatId: string, chatParticipant: string) => void;
badge?: {
count?: number;
};
}
export type Group = GroupInfoDTO| GroupDTO | undefined;
export type Group = GroupInfoDTO | GroupDTO | undefined;

export interface IChatPreviewListProps {
overrideAccount?: string;
listType?: 'CHATS' | 'REQUESTS' | 'SEARCH';
prefillChatPreviewList?: Array<IChatPreviewProps>;
searchParamter?: string;
onChatSelected?: (chatId: string,chatParticipant: string) => void;
onChatSelected?: (chatId: string, chatParticipant: string) => void;
onUnreadCountChange?: (count: number) => void;
onPreload?: (chats: Array<IChatPreviewPayload>) => void;
onPaging?: (chats: Array<IChatPreviewPayload>) => void;
onLoading?: (loadingData:{loading:boolean,preload:boolean,paging:boolean,finished:boolean}) => void;
onLoading?: (loadingData: {
loading: boolean;
preload: boolean;
paging: boolean;
finished: boolean;
}) => void;
}

export interface IChatViewListProps {
Expand All @@ -43,7 +52,6 @@ export interface IChatViewListProps {
limit?: number;
}


export interface IChatViewComponentProps {
messageInput?: boolean;
chatViewList?: boolean;
Expand All @@ -55,15 +63,15 @@ export interface IChatViewComponentProps {
gif?: boolean;
file?: boolean;
isConnected?: boolean;
autoConnect?:boolean;
autoConnect?: boolean;
groupInfoModalBackground?: ModalBackgroundType;
groupInfoModalPositionType?: ModalPositionType;
verificationFailModalBackground?: ModalBackgroundType;
verificationFailModalPosition?: ModalPositionType;
onVerificationFail?: () => void;
chatProfileRightHelperComponent?: React.ReactNode;
chatProfileLeftHelperComponent?: React.ReactNode;
welcomeComponent?:React.ReactNode;
welcomeComponent?: React.ReactNode;
}

export interface IChatProfile {
Expand Down Expand Up @@ -103,28 +111,25 @@ export interface MessageInputProps {
gif?: boolean;
file?: boolean;
isConnected?: boolean;
autoConnect?:boolean;
autoConnect?: boolean;
verificationFailModalBackground?: ModalBackgroundType;
verificationFailModalPosition?: ModalPositionType;
onVerificationFail?: () => void;
}




export interface MessageIPFS {
fromCAIP10: string
toCAIP10: string
fromDID: string
toDID: string
messageType: string
messageContent: string
signature: string
sigType: string
link: string | null
timestamp?: number
encType: string
encryptedSecret: string
fromCAIP10: string;
toCAIP10: string;
fromDID: string;
toDID: string;
messageType: string;
messageContent: string;
signature: string;
sigType: string;
link: string | null;
timestamp?: number;
encType: string;
encryptedSecret: string;
}

export interface Feeds {
Expand All @@ -141,7 +146,7 @@ export interface Feeds {
intentTimestamp: Date;
combinedDID: string;
cid?: string;
groupInformation?: IGroup
groupInformation?: IGroup;
}

export interface User {
Expand All @@ -158,26 +163,26 @@ export interface User {
numMsg: number;
allowedNumMsg: number;
linkedListHash?: string | null;
isAdmin?:boolean;
isAdmin?: boolean;
}

export interface CreateGroupModalProps {
onClose: ()=>void;
onClose: () => void;
modalBackground?: ModalBackgroundType;
modalPositionType?: ModalPositionType;
};
onSuccess?: (group: GroupInfoDTO | GroupDTO | undefined) => void;
}

export interface UserProfileProps {
updateUserProfileModalBackground?: ModalBackgroundType;
updateUserProfileModalPositionType?: ModalPositionType;
};
}

export interface ModalButtonProps {
memberListCount?: boolean;
theme?: IChatTheme;
isLoading?: boolean;
};

}

export { IChatTheme } from './theme';

Expand All @@ -201,4 +206,4 @@ export enum ChatPreviewListErrorCodes {
export interface IChatPreviewListError {
code: ChatPreviewListErrorCodes;
message: string;
}
}
17 changes: 10 additions & 7 deletions packages/uiweb/src/lib/hooks/chat/useCreateGatedGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,27 @@ export const useCreateGatedGroup = () => {
const { env, account, user } = useChatData();

const createGatedGroup = useCallback(
async (groupInfoType:GrouInfoType,rules: any) => {
async (groupInfoType: GrouInfoType, rules: any) => {
setLoading(true);
console.debug('user in create group ',user)
try {
const payload = {
description:groupInfoType.groupDescription,
image:groupInfoType.groupImage,
description: groupInfoType.groupDescription,
image: groupInfoType.groupImage,
private: !groupInfoType.isPublic,
members: groupInfoType.members,
admins: groupInfoType.admins,
rules: rules,
};
const response = await user?.chat.group.create(groupInfoType.groupName, payload);
const response = await user?.chat.group.create(
groupInfoType.groupName,
payload
);
setLoading(false);
if (!response) {
return false;
return { success: false, data: 'Something went wrong' };
}
return true;
return { success: true, data: response };
} catch (error: Error | any) {
setLoading(false);
setError(error.message);
Expand All @@ -37,4 +40,4 @@ export const useCreateGatedGroup = () => {
);

return { createGatedGroup, error, loading };
};
};

0 comments on commit 241080d

Please sign in to comment.