creating link successfully
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { FaArchive, FaExternalLinkAlt, FaFilePdf } from "react-icons/fa";
|
import { FaArchive, FaExternalLinkAlt, FaFilePdf } from "react-icons/fa";
|
||||||
import Link from "../models/link";
|
import Link, { LinkType } from "../models/link";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { BsThreeDots } from "react-icons/bs";
|
import { BsThreeDots } from "react-icons/bs";
|
||||||
import LinkIcon from "./LinkIcon";
|
import LinkIcon from "./LinkIcon";
|
||||||
@@ -9,7 +9,10 @@ export default function LinkCard(props: { link?: Link }) {
|
|||||||
<span className="flex flex-col rounded-lg">
|
<span className="flex flex-col rounded-lg">
|
||||||
{/* attmnt header */}
|
{/* attmnt header */}
|
||||||
<span className="flex flex-row bg-gray-300 bg-opacity-25 py-5 px-3 items-center justify-start">
|
<span className="flex flex-row bg-gray-300 bg-opacity-25 py-5 px-3 items-center justify-start">
|
||||||
<LinkIcon className="text-4xl text-orange-300 mr-2" />
|
<LinkIcon
|
||||||
|
className="text-4xl text-orange-300 mr-2"
|
||||||
|
linkType={LinkType.googleDrive}
|
||||||
|
/>
|
||||||
|
|
||||||
<span className="flex flex-col items-baseline mr-10 space-y-1">
|
<span className="flex flex-col items-baseline mr-10 space-y-1">
|
||||||
<span className="text-md font-bold text-white">report.pdf</span>
|
<span className="text-md font-bold text-white">report.pdf</span>
|
||||||
|
|||||||
@@ -11,8 +11,11 @@ import {
|
|||||||
} from "../../contexts/keyboardContext";
|
} from "../../contexts/keyboardContext";
|
||||||
import { useTeamDashboardContext } from "../../contexts/teamDashboardContext";
|
import { useTeamDashboardContext } from "../../contexts/teamDashboardContext";
|
||||||
import Link, { LinkType } from "../../models/link";
|
import Link, { LinkType } from "../../models/link";
|
||||||
|
import { SendService } from "../../services/sendService";
|
||||||
import LinkIcon from "../LinkIcon";
|
import LinkIcon from "../LinkIcon";
|
||||||
|
|
||||||
|
const sendService = new SendService();
|
||||||
|
|
||||||
export default function CreateOrUpdateLink() {
|
export default function CreateOrUpdateLink() {
|
||||||
const { currUser } = useAuth();
|
const { currUser } = useAuth();
|
||||||
const { handleModalType, showModalType } = useKeyboardContext();
|
const { handleModalType, showModalType } = useKeyboardContext();
|
||||||
@@ -41,12 +44,22 @@ export default function CreateOrUpdateLink() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSubmitLink() {
|
async function handleSubmitLink() {
|
||||||
if (!link || !name) {
|
if (!link || !name) {
|
||||||
toast.error("Please add a valid link and name");
|
toast.error("Please add a valid link and name");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
!isTeamLink &&
|
||||||
|
(!recipientsSelected || recipientsSelected.length == 0)
|
||||||
|
) {
|
||||||
|
toast.error(
|
||||||
|
"Please select members or send it to the team with the toggle"
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// if it's a team link, make sure recipients is null ... but the model should handle this for us?
|
// if it's a team link, make sure recipients is null ... but the model should handle this for us?
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -59,15 +72,29 @@ export default function CreateOrUpdateLink() {
|
|||||||
currUser.uid
|
currUser.uid
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log(newLink);
|
handleModalType(ShowModalType.na);
|
||||||
|
|
||||||
// send to database
|
// send to database
|
||||||
|
await sendService.sendLink(newLink);
|
||||||
|
|
||||||
|
resetForm();
|
||||||
|
|
||||||
|
toast.success("link sent");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error("Something went wrong in sending the link.");
|
toast.error("Something went wrong in sending the link.");
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetForm() {
|
||||||
|
setLink("");
|
||||||
|
setName("");
|
||||||
|
setDescription("");
|
||||||
|
setShowMoreDetails(false);
|
||||||
|
setIsTeamLink(true);
|
||||||
|
setRecipientsSelected([]);
|
||||||
|
}
|
||||||
|
|
||||||
const [link, setLink] = useState<string>("");
|
const [link, setLink] = useState<string>("");
|
||||||
const [name, setName] = useState<string>("");
|
const [name, setName] = useState<string>("");
|
||||||
const [description, setDescription] = useState<string>("");
|
const [description, setDescription] = useState<string>("");
|
||||||
|
|||||||
+6
-12
@@ -11,7 +11,7 @@ export default class Link {
|
|||||||
|
|
||||||
teamId: string;
|
teamId: string;
|
||||||
// if it's not a teamAttachment, then have a list of members who it's for
|
// if it's not a teamAttachment, then have a list of members who it's for
|
||||||
private _recipients: string[]; // userIds
|
recipients: string[]; // userIds
|
||||||
|
|
||||||
createdByUserId: string;
|
createdByUserId: string;
|
||||||
createdDate: Timestamp;
|
createdDate: Timestamp;
|
||||||
@@ -31,19 +31,13 @@ export default class Link {
|
|||||||
this.recipients = recipientsArr;
|
this.recipients = recipientsArr;
|
||||||
this.createdByUserId = _createdByUserId;
|
this.createdByUserId = _createdByUserId;
|
||||||
|
|
||||||
this.type = Link.getLinkType(_link);
|
if (!recipientsArr || recipientsArr?.length == 0) {
|
||||||
}
|
this.recipients = null;
|
||||||
|
|
||||||
public get recipients(): string[] {
|
|
||||||
return this._recipients;
|
|
||||||
}
|
|
||||||
|
|
||||||
public set recipients(arrUserIds: string[]) {
|
|
||||||
if (!this._recipients || this._recipients?.length == 0) {
|
|
||||||
this._recipients = null;
|
|
||||||
} else {
|
} else {
|
||||||
this._recipients = arrUserIds;
|
this.recipients = recipientsArr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.type = Link.getLinkType(_link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getLinkType(url: string): LinkType {
|
static getLinkType(url: string): LinkType {
|
||||||
|
|||||||
@@ -7,5 +7,5 @@ export enum Collections {
|
|||||||
|
|
||||||
rooms = "rooms",
|
rooms = "rooms",
|
||||||
announcements = "announcements",
|
announcements = "announcements",
|
||||||
attachments = "attachments",
|
links = "links",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
getFirestore,
|
getFirestore,
|
||||||
serverTimestamp,
|
serverTimestamp,
|
||||||
} from "firebase/firestore";
|
} from "firebase/firestore";
|
||||||
|
import Link from "../models/link";
|
||||||
import { Message } from "../models/message";
|
import { Message } from "../models/message";
|
||||||
import { Collections } from "./collections";
|
import { Collections } from "./collections";
|
||||||
|
|
||||||
@@ -23,4 +24,11 @@ export class SendService {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async sendLink(link: Link) {
|
||||||
|
await addDoc(collection(this.db, Collections.links), {
|
||||||
|
...link,
|
||||||
|
createdDate: serverTimestamp(),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user