creating link successfully
This commit is contained in:
@@ -11,8 +11,11 @@ import {
|
||||
} from "../../contexts/keyboardContext";
|
||||
import { useTeamDashboardContext } from "../../contexts/teamDashboardContext";
|
||||
import Link, { LinkType } from "../../models/link";
|
||||
import { SendService } from "../../services/sendService";
|
||||
import LinkIcon from "../LinkIcon";
|
||||
|
||||
const sendService = new SendService();
|
||||
|
||||
export default function CreateOrUpdateLink() {
|
||||
const { currUser } = useAuth();
|
||||
const { handleModalType, showModalType } = useKeyboardContext();
|
||||
@@ -41,12 +44,22 @@ export default function CreateOrUpdateLink() {
|
||||
}
|
||||
}
|
||||
|
||||
function handleSubmitLink() {
|
||||
async function handleSubmitLink() {
|
||||
if (!link || !name) {
|
||||
toast.error("Please add a valid link and name");
|
||||
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?
|
||||
|
||||
try {
|
||||
@@ -59,15 +72,29 @@ export default function CreateOrUpdateLink() {
|
||||
currUser.uid
|
||||
);
|
||||
|
||||
console.log(newLink);
|
||||
handleModalType(ShowModalType.na);
|
||||
|
||||
// send to database
|
||||
await sendService.sendLink(newLink);
|
||||
|
||||
resetForm();
|
||||
|
||||
toast.success("link sent");
|
||||
} catch (error) {
|
||||
toast.error("Something went wrong in sending the link.");
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
function resetForm() {
|
||||
setLink("");
|
||||
setName("");
|
||||
setDescription("");
|
||||
setShowMoreDetails(false);
|
||||
setIsTeamLink(true);
|
||||
setRecipientsSelected([]);
|
||||
}
|
||||
|
||||
const [link, setLink] = useState<string>("");
|
||||
const [name, setName] = useState<string>("");
|
||||
const [description, setDescription] = useState<string>("");
|
||||
|
||||
Reference in New Issue
Block a user