diff --git a/packages/uiweb/src/lib/components/chat/CreateGroup/AddCriteria.tsx b/packages/uiweb/src/lib/components/chat/CreateGroup/AddCriteria.tsx index f99fa58b2..1c893821f 100644 --- a/packages/uiweb/src/lib/components/chat/CreateGroup/AddCriteria.tsx +++ b/packages/uiweb/src/lib/components/chat/CreateGroup/AddCriteria.tsx @@ -266,6 +266,7 @@ const AddCriteria = ({ } as DropdownValueType) } + const onQuantityChange = (e: any) => { setQuantity({ ...quantity, value: e.target.value }); }; diff --git a/packages/uiweb/src/lib/components/chat/CreateGroup/CreateGroupModal.tsx b/packages/uiweb/src/lib/components/chat/CreateGroup/CreateGroupModal.tsx index 7534d0a13..4114e71f5 100644 --- a/packages/uiweb/src/lib/components/chat/CreateGroup/CreateGroupModal.tsx +++ b/packages/uiweb/src/lib/components/chat/CreateGroup/CreateGroupModal.tsx @@ -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, @@ -61,6 +55,7 @@ export const CreateGroupModal: React.FC = ({ onClose, modalBackground = MODAL_BACKGROUND_TYPE.OVERLAY, modalPositionType = MODAL_POSITION_TYPE.GLOBAL, + onSuccess, }) => { const [activeComponent, setActiveComponent] = useState( // replace it with info one @@ -107,7 +102,6 @@ export const CreateGroupModal: React.FC = ({ }); const [isImageUploaded, setIsImageUploaded] = useState(false); - const showError = (errorMessage: string) => { groupInfoToast.showMessageToast({ toastTitle: 'Error', @@ -118,7 +112,7 @@ export const CreateGroupModal: React.FC = ({ }; const getEncryptionType = () => { - console.debug(groupInputDetails.groupEncryptionType, "encryptionTypeee"); + console.debug(groupInputDetails.groupEncryptionType, 'encryptionTypeee'); if (groupInputDetails.groupEncryptionType === 'encrypted') { return false; } @@ -139,8 +133,10 @@ export const CreateGroupModal: React.FC = ({ .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', @@ -211,7 +207,7 @@ export const CreateGroupModal: React.FC = ({ onClose={onClose} /> ); - + case CREATE_GROUP_STEP_KEYS.ADD_MEMBERS: return ( = ({ 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 ( @@ -264,7 +261,9 @@ export interface ModalHeaderProps { handleAddWallets?: () => void; isImageUploaded?: boolean; setIsImageUploaded?: React.Dispatch>; - setGroupInputDetails?: React.Dispatch>; + setGroupInputDetails?: React.Dispatch< + React.SetStateAction + >; groupInputDetails?: GroupInputDetailsType; } @@ -494,4 +493,4 @@ const ErrorSpan = styled(Span)` font-size: 12px; font-weight: 500; color: #ed5858; -`; \ No newline at end of file +`; diff --git a/packages/uiweb/src/lib/components/chat/exportedTypes.ts b/packages/uiweb/src/lib/components/chat/exportedTypes.ts index e389a3f80..cccffd782 100644 --- a/packages/uiweb/src/lib/components/chat/exportedTypes.ts +++ b/packages/uiweb/src/lib/components/chat/exportedTypes.ts @@ -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; @@ -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; searchParamter?: string; - onChatSelected?: (chatId: string,chatParticipant: string) => void; + onChatSelected?: (chatId: string, chatParticipant: string) => void; onUnreadCountChange?: (count: number) => void; onPreload?: (chats: Array) => void; onPaging?: (chats: Array) => 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 { @@ -43,7 +52,6 @@ export interface IChatViewListProps { limit?: number; } - export interface IChatViewComponentProps { messageInput?: boolean; chatViewList?: boolean; @@ -55,7 +63,7 @@ export interface IChatViewComponentProps { gif?: boolean; file?: boolean; isConnected?: boolean; - autoConnect?:boolean; + autoConnect?: boolean; groupInfoModalBackground?: ModalBackgroundType; groupInfoModalPositionType?: ModalPositionType; verificationFailModalBackground?: ModalBackgroundType; @@ -63,7 +71,7 @@ export interface IChatViewComponentProps { onVerificationFail?: () => void; chatProfileRightHelperComponent?: React.ReactNode; chatProfileLeftHelperComponent?: React.ReactNode; - welcomeComponent?:React.ReactNode; + welcomeComponent?: React.ReactNode; } export interface IChatProfile { @@ -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 { @@ -141,7 +146,7 @@ export interface Feeds { intentTimestamp: Date; combinedDID: string; cid?: string; - groupInformation?: IGroup + groupInformation?: IGroup; } export interface User { @@ -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'; @@ -201,4 +206,4 @@ export enum ChatPreviewListErrorCodes { export interface IChatPreviewListError { code: ChatPreviewListErrorCodes; message: string; -} \ No newline at end of file +} diff --git a/packages/uiweb/src/lib/hooks/chat/useCreateGatedGroup.ts b/packages/uiweb/src/lib/hooks/chat/useCreateGatedGroup.ts index 25ff2253f..48b8dd16b 100644 --- a/packages/uiweb/src/lib/hooks/chat/useCreateGatedGroup.ts +++ b/packages/uiweb/src/lib/hooks/chat/useCreateGatedGroup.ts @@ -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); @@ -37,4 +40,4 @@ export const useCreateGatedGroup = () => { ); return { createGatedGroup, error, loading }; -}; \ No newline at end of file +};