Skip to content

Commit

Permalink
feat: group msg fix (#765)
Browse files Browse the repository at this point in the history
* feat: group msg fix

* fix: minor changes

---------

Co-authored-by: Monalisha Mishra <[email protected]>
  • Loading branch information
MdTeach and mishramonalisha76 authored Oct 10, 2023
1 parent 356487f commit db0a47d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ export const CreateGroupModal: React.FC<CreateGroupModalProps> = ({

const [groupInputDetails, setGroupInputDetails] =
useState<GroupInputDetailsType>({
groupName: 'Push Group Chat',
groupDescription: 'This is the oficial group for Push Protocol',
groupImage: ProfilePicture,
groupName: '',
groupDescription: '',
groupImage: '',
});

const renderComponent = () => {
Expand Down Expand Up @@ -216,10 +216,10 @@ const CreateGroupDetail = ({
}

// verify description
if (!groupImage) {
showError("Group image can't be empty");
return;
}
// if (!groupImage) {
// showError("Group image can't be empty");
// return;
// }
}

if (handleNext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { GrouInfoType as GroupInfoType } from '../types';

import { ACCESS_TYPE_TITLE } from '../constants';
import { IChatTheme } from '../exportedTypes';
import { ProfilePicture } from '../../../config';

const GROUP_TYPE_OPTIONS: Array<OptionDescription> = [
{
Expand Down Expand Up @@ -52,7 +53,6 @@ const AddConditionSection = ({
criteriaState,
}: AddConditionProps) => {
const theme = useContext(ThemeContext);
//todo - dummy data to be removed after we get condition data

const generateMapping = () => {
return criteriaState.entryOptionsDataArray.map((rule, idx) => [
Expand Down Expand Up @@ -151,31 +151,41 @@ export const CreateGroupType = ({
const { createGatedGroup, loading } = useCreateGatedGroup();
const groupInfoToast = useToast();

const getEncryptionType = () =>{
if(groupEncryptionType === "encrypted"){
return false
}
return true
}

const createGroupService = async () => {
// TODO:use actual data instead of dummy data
const groupInfo:GroupInfoType = {
groupName:groupInputDetails.groupName,
groupDescription:groupInputDetails.groupDescription,
groupImage:groupInputDetails.groupImage,
isPublic: true //groupEncryptionType,
groupImage:groupInputDetails.groupImage || ProfilePicture,
isPublic: getEncryptionType(),
};
const rules: any = criteriaStateManager.generateRule();
await createGatedGroup(groupInfo, rules);
groupInfoToast.showMessageToast({
toastTitle: 'Success',
toastMessage: 'Group created successfully',
toastType: 'SUCCESS',
getToastIcon: (size) => <MdCheckCircle size={size} color="green" />,
});
const rules: any = checked ? criteriaStateManager.generateRule() : {};
const isSuccess = await createGatedGroup(groupInfo, rules);
if(isSuccess === true){
groupInfoToast.showMessageToast({
toastTitle: 'Success',
toastMessage: 'Group created successfully',
toastType: 'SUCCESS',
getToastIcon: (size) => <MdCheckCircle size={size} color="green" />,
});
}else{
showError('Group creation failed');
}

onClose();
};

const verifyAndCreateGroup = async () => {
// TODO:validate the fields
// if (groupEncryptionType.trim() === '') {
// showError('Group encryption type is not selected');
// return;
// }
if (groupEncryptionType.trim() === '') {
showError('Group encryption type is not selected');
return;
}

await createGroupService();
};
Expand Down
2 changes: 1 addition & 1 deletion packages/uiweb/src/lib/hooks/chat/useCreateGatedGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export const useCreateGatedGroup = () => {
if (!response) {
return false;
}
return true;
} catch (error: Error | any) {
setLoading(false);
setError(error.message);
console.log(error);
return error.message;
}
},
Expand Down

0 comments on commit db0a47d

Please sign in to comment.