Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(uiweb): return response in createGroupModal #1198

Merged
merged 3 commits into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -482,4 +481,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,23 +9,26 @@ export const useCreateGatedGroup = () => {
const { env, account, user } = useChatData();

const createGatedGroup = useCallback(
async (groupInfoType:GrouInfoType,rules: any) => {
async (groupInfoType: GrouInfoType, rules: any) => {
setLoading(true);
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 @@ -36,4 +39,4 @@ export const useCreateGatedGroup = () => {
);

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