Skip to content

Commit

Permalink
added chats changing
Browse files Browse the repository at this point in the history
  • Loading branch information
dendidibe committed Aug 7, 2023
1 parent a46c8b7 commit f8087e0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
9 changes: 9 additions & 0 deletions client-web/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export interface IDefaultChatRoom {
pinned: boolean;
title: string;
}
export interface IUserDefaults {
defaultAccessProfileOpen: boolean,
defaultAccessAssetsOpen: boolean,
usersCanFree: boolean,
defaultRooms: Omit<IDefaultChatRoom, 'title'>[]
}
export type TUser = {
firstName: string;
lastName: string;
Expand Down Expand Up @@ -569,6 +575,9 @@ export function loginOwner(email: string, password: string) {
export function getApps() {
return httpWithAuth().get("/apps");
}
export function changeUserDefaults(appId: string, data: IUserDefaults) {
return httpWithAuth().put("/apps/user-defaults/" + appId, data);
}
export function getDefaultChats() {
const appToken = useStoreState.getState().config.appToken;

Expand Down
29 changes: 14 additions & 15 deletions client-web/src/pages/AppEdit/UserDefaults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import xmpp from "../../xmpp";
import { CONFERENCEDOMAIN } from "../../constants";
export interface IUserDefaults {}

const JID_LENGTH = 64;
const JID_LENGTH = 64 + CONFERENCEDOMAIN.length;

export const UserDefaults: React.FC<IUserDefaults> = ({}) => {
const fileRef = React.useRef<HTMLInputElement>(null);
Expand Down Expand Up @@ -58,24 +58,25 @@ export const UserDefaults: React.FC<IUserDefaults> = ({}) => {
{ setSubmitting }
) => {
setSubmitting(true);
const fd = new FormData();
const defaultRooms = defaultChatRooms.map((room) => ({
jid: room.jid,
pinned: room.checked,
}));
fd.append("displayName", app.displayName);
fd.append("defaultAccessAssetsOpen", defaultAccessAssetsOpen.toString());
fd.append(
"defaultAccessProfileOpen",
defaultAccessProfileOpen.toString()
);
fd.append("usersCanFree", usersCanFree.toString());
fd.append("defaultRooms", JSON.stringify(defaultRooms));
const body = {
defaultAccessProfileOpen: defaultAccessProfileOpen,
defaultAccessAssetsOpen: defaultAccessAssetsOpen,
usersCanFree: usersCanFree,
defaultRooms: defaultRooms,
};

try {
const res = await http.updateAppSettings(appId, fd);
const res = await http.changeUserDefaults(appId, body);
console.log(res.data)
setUser({ ...user, homeScreen: "" });
updateApp(res.data.result);
updateApp(res.data);
showSnackbar('success', 'User Defaults updated successfully')
} catch (error) {
console.log(error)
showSnackbar(
"error",
"Cannot update the app " + (error.response?.data?.error || "")
Expand Down Expand Up @@ -104,9 +105,7 @@ export const UserDefaults: React.FC<IUserDefaults> = ({}) => {
const rooms = [...defaultChatRooms];
rooms[i][property] = value;
if (property === "jid" && value.length === JID_LENGTH) {
const isRoomExistsStanza = await xmpp.getAndReceiveRoomInfo(
value + CONFERENCEDOMAIN
);
const isRoomExistsStanza = await xmpp.getAndReceiveRoomInfo(value);
//error appears because room is not exist and we can create it
if (isRoomExistsStanza.children[1]?.["name"] !== "error") {
rooms[i].error = true;
Expand Down

0 comments on commit f8087e0

Please sign in to comment.