Skip to content

Commit

Permalink
Fixed File Upload Error
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalmohib committed May 5, 2023
1 parent bd5a682 commit 8f9e6eb
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 226 deletions.
78 changes: 41 additions & 37 deletions components/Main/Inbox/AddUserModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const AddUserModal: React.FC<AddUserModalProps> = ({
getOptionLabel: (option: ProjectMemberOptionType) => option.title,
};

const [value, setValue] = React.useState<ProjectMemberOptionType | null>(null);
const [value, setValue] = React.useState<any>(null);

useEffect(() => {
if (value) {
Expand All @@ -64,47 +64,51 @@ const AddUserModal: React.FC<AddUserModalProps> = ({

const handleStartNewChat = () => {
console.log("Start New Chat");
// alert("value" + " " + value?.title);
setIsOpen(false);

// Extract user name from email
let name = value?.title.split("@")[0];

const chatUser = {
uid: value?.title,
email: value?.title,
name: name,
lastMessage: '',
lastMessageTime: new Date().toLocaleTimeString(),
profilePic: "/static/images/avatar/1.jpg",
isOnline: true
}
if (value !== null) {
// alert("value" + " " + value?.title);
setIsOpen(false);

// Extract user name from email
let name = value?.title.split("@")[0];

const chatUser = {
uid: value.title,
email: value.title,
name: name,
lastMessage: 'Hi',
lastMessageTime: new Date().toLocaleTimeString(),
profilePic: "/static/images/avatar/1.jpg",
isOnline: true
}

console.log("UsersListSingleChat ===> ", usersListSingleChat);
console.log("UsersListSingleChat ===> ", usersListSingleChat);

// Check if user already exists in the database by checking the value in the
// projectMembersState array
let userExists = false;
for (let i = 0; i < usersListSingleChat.length; i++) {
if (usersListSingleChat[i]?.email == value?.title) {
userExists = true;
break;
// Check if user already exists in the database by checking the value in the
// projectMembersState array
let userExists = false;
for (let i = 0; i < usersListSingleChat.length; i++) {
if (usersListSingleChat[i]?.email == value?.title) {
userExists = true;
break;
}
}
}

if (userExists) {
// Show the alert that user already exists
alert("User already exists");
return;
if (userExists) {
// Show the alert that user already exists
alert("User already exists");
return;
} else {
// Add user to the chat list
addData(
chatUser,
"singleUser",
isSignedIn,
signedInUserData,
enqueueSnackbar
);
}
} else {
// Add user to the chat list
addData(
chatUser,
"singleUser",
isSignedIn,
signedInUserData,
enqueueSnackbar
);
alert("Please select a user");
}
}

Expand Down
11 changes: 7 additions & 4 deletions components/Main/Inbox/InteractiveContainer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,19 @@ const InteractiveContainer: React.FC<InteractiveContainerProps> = ({
const [percent, setPercent] = useState(0);

// Handle file upload event and update state
const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const handleFileChange = (event: any) => {
if (event.target.files && event.target.files.length > 0) {
setFile(event.target.files[0]);
}
// @ts-ignore
const storageRef = ref(storage, `/files/${file?.name}`);

let uploadedFileName: string = event?.target?.files[0].name;
let uploadedFile = event?.target?.files[0];

const storageRef = ref(storage, `/files/${uploadedFileName}`);

// progress can be paused and resumed. It also exposes progress updates.
// Receives the storage reference and the file to upload.
const uploadTask = uploadBytesResumable(storageRef, file!);
const uploadTask = uploadBytesResumable(storageRef, uploadedFile);

uploadTask.on(
"state_changed",
Expand Down
70 changes: 52 additions & 18 deletions components/Main/Inbox/MessageContainer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { Box, Tooltip } from '@mui/material';
import styles from './style.module.css';
import Image from 'next/image';
import DateCategorizationChat from '../DateCategorizationChat';

import styles from './style.module.css';
interface MessageContainerProps {
editedMessageId: number,
userName: string,
Expand All @@ -11,6 +12,7 @@ interface MessageContainerProps {
id: string,
userPic: string,
type: string,
messageType: string
}

const MessageContainer: React.FC<MessageContainerProps> = ({
Expand All @@ -21,6 +23,7 @@ const MessageContainer: React.FC<MessageContainerProps> = ({
userPic,
id,
type,
messageType
}) => {
console.log("the user pictuyre ==> " + userPic)
return (
Expand Down Expand Up @@ -66,23 +69,54 @@ const MessageContainer: React.FC<MessageContainerProps> = ({
</p>
</div>
<Tooltip title={timeSent} placement="top">
<div style={{
backgroundColor:
(type === "sent") ? (
'#058760'
) : (type === "received") ? (
'#055587'
) : (""),
borderRadius: '10px',
width: 'fit-content',
maxWidth: '80%',
paddingRight: '10px',
marginLeft: '10px',
}}
>
<p style={{ paddingTop: '10px', paddingBottom: '10px' }} className={styles.Middlemessage}>
{message}
</p>
<div>
{(messageType === 'text') && (
<div
style={{
backgroundColor:
(type === "sent") ? (
'#058760'
) : (type === "received") ? (
'#055587'
) : (""),
borderRadius: '10px',
width: 'fit-content',
maxWidth: '80%',
paddingRight: '10px',
marginLeft: '10px',
}}
>
<p style={{ paddingTop: '10px', paddingBottom: '10px' }} className={styles.Middlemessage}>
{message}
</p>
</div>
)}
{(messageType === 'file') && (
<div
style={{
backgroundColor: "transparent",
borderRadius: '10px',
width: 'fit-content',
maxWidth: '80%',
marginLeft: '10px',
// border: "1px solid red"
}}
>
<Image
src={message}
alt={`Image sent by user ${userName}`}
title={`Image sent by user ${userName}`}
width={500}
height={300}
style={{
height: 'auto !important',
width: 'auto !important',
borderRadius: '10px',
}}
loading='eager'
/>
</div>
)}
</div>
</Tooltip>
</Box>
Expand Down
9 changes: 5 additions & 4 deletions components/Main/Inbox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const Inbox: React.FC<InboxProps> = ({ email }) => {
});

// For getting the UsersListSingleChat
const [usersListSingleChat, setUsersListSingleChat] = useState<any>([]);
const [usersListSingleChat, setUsersListSingleChat] = useState<any>(null);

// Data/Chat/Single/Users${dataObject.email}

Expand Down Expand Up @@ -128,7 +128,7 @@ const Inbox: React.FC<InboxProps> = ({ email }) => {

// FOR GETTING PROJECTS
useEffect(() => {
if (!loading) {
if (!loading && signedInUserData !== null && snapshot !== undefined) {
let projectMembers = [];

let localObj: any;
Expand All @@ -144,7 +144,7 @@ const Inbox: React.FC<InboxProps> = ({ email }) => {
// localObj = localObj.filter((project: any) => );

// Filter the projects array and extract only those projects that are shared with me
localObj = localObj.filter((project: any) => project?.ProjectMembers?.includes(email) || project?.createdBy === email);
localObj = localObj.filter((project: any) => project?.ProjectMembers?.includes(signedInUserData.email) || project?.createdBy === signedInUserData.email);

let tempProjectsObj: any = localObj;

Expand Down Expand Up @@ -635,7 +635,7 @@ const Inbox: React.FC<InboxProps> = ({ email }) => {
backgroundColor: "#fff",
}}
>
{usersListSingleChat.length === 0 ? (
{usersListSingleChat === null ? (
<Box
sx={{
display: "flex",
Expand Down Expand Up @@ -1114,6 +1114,7 @@ const Inbox: React.FC<InboxProps> = ({ email }) => {
"received"
)
}
messageType={(item.type) ? (item.type) : ("text")}
// ref={messagesEndRef}
/>
</Box>
Expand Down
4 changes: 2 additions & 2 deletions components/Main/Reporting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ const Reporting: React.FC<ReportingProps> = ({
// FOR GETTING PROJECTS
useEffect(() => {

if (!loading) {
if (!loading && snapshot && signedInUserData !== null) {
let projectMembers = [];

let localObj: any;
Expand All @@ -279,7 +279,7 @@ const Reporting: React.FC<ReportingProps> = ({
// localObj = localObj.filter((project: any) => );

// Filter the projects array and extract only those projects that are shared with me
localObj = localObj.filter((project: any) => project?.ProjectMembers?.includes(email) || project?.createdBy === email);
localObj = localObj.filter((project: any) => project?.ProjectMembers?.includes(signedInUserData.email) || project?.createdBy === signedInUserData.email);

let tempProjectsObj: any = localObj;

Expand Down
4 changes: 2 additions & 2 deletions components/Widgets/Widget1/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const Widget1: React.FC<IProps> = ({
// FOR GETTING PROJECTS
useEffect(() => {

if (!loading) {
if (!loading && snapshot && signedInUserData) {
let localObj: any;

let arrProjects = snapshot?.docs.map(doc => ({ ...doc.data(), id: doc.id }));
Expand All @@ -135,7 +135,7 @@ const Widget1: React.FC<IProps> = ({
// localObj = localObj.filter((project: any) => );

// Filter the projects array and extract only those projects that are shared with me
localObj = localObj.filter((project: any) => project?.ProjectMembers?.includes(email) || project?.createdBy === email);
localObj = localObj.filter((project: any) => project?.ProjectMembers?.includes(signedInUserData.email) || project?.createdBy === signedInUserData.email);

// Extract all the project members from the projects array
setProjects(localObj);
Expand Down
15 changes: 7 additions & 8 deletions firebase/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ const firebaseConfig = {
// appId: process.env.REACT_APP_APP_ID,
// measurementId: process.env.REACT_APP_MEASUREMENT_ID

apiKey: "AIzaSyCizj_hKFU4s6cqVt3GTf18W9oMn9G-4pA",
authDomain: "architectsstaffmanager.firebaseapp.com",
databaseURL: "https://architectsstaffmanager-default-rtdb.firebaseio.com",
projectId: "architectsstaffmanager",
storageBucket: "architectsstaffmanager.appspot.com",
messagingSenderId: "550911242330",
appId: "1:550911242330:web:5c5fc2e0a60ea05c3be863",
measurementId: "G-483Y28377N",
apiKey: "AIzaSyC73jJz3lqIO_qTnbV8ei4OLPygL1QRzaI",
authDomain: "taskencher.firebaseapp.com",
projectId: "taskencher",
storageBucket: "taskencher.appspot.com",
messagingSenderId: "1052740073596",
appId: "1:1052740073596:web:548143663a11c4cce5b1f9",
measurementId: "G-L0F850N8Z9",
};

// Initialize Firebase
Expand Down
Loading

1 comment on commit 8f9e6eb

@vercel
Copy link

@vercel vercel bot commented on 8f9e6eb May 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.