From e0d1c43ea49525514ea8a019d1cf79e0baec69ad Mon Sep 17 00:00:00 2001 From: Noah Templet Date: Tue, 12 Sep 2023 22:49:23 -0500 Subject: [PATCH] Linktree functionality --- src/pages/Links/Links.jsx | 49 ++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/src/pages/Links/Links.jsx b/src/pages/Links/Links.jsx index 2ac0128..e81382d 100644 --- a/src/pages/Links/Links.jsx +++ b/src/pages/Links/Links.jsx @@ -1,4 +1,4 @@ -import React, { useState } from "react" +import React, { useState, useEffect } from "react" import { Container, Row, Col, Table, Button, Modal, ModalHeader, ModalBody, ModalFooter, Input, Label, Form, FormGroup } from "reactstrap" import { FontAwesomeIcon } from "@fortawesome/react-fontawesome" @@ -16,6 +16,18 @@ const LinkModal = ({ modal, toggle, currentlyEdited, ...args }) => { const [fields, setFields] = useState(defaultFields); + useEffect(() => { + if (currentlyEdited == null) + setFields(defaultFields); + else + setFields({ + linkName: currentlyEdited.linkName, + linkUrl: currentlyEdited.linkUrl, + logoAlt: currentlyEdited.logoAlt, + logoUrl: currentlyEdited.logoUrl + }); + }, [currentlyEdited]); + const updateField = (key, value) => { var newFields = { ...fields }; @@ -24,7 +36,19 @@ const LinkModal = ({ modal, toggle, currentlyEdited, ...args }) => { setFields(newFields) } - console.log(fields) + const submitUpdates = e => { + e.preventDefault(); + + var id = currentlyEdited == null ? undefined : currentlyEdited.id; + + console.log(fields); + + request(`/link`, { ...fields, linkId: id }, currentlyEdited == null ? "POST" : "PATCH", true, 'application/json') + .then(() => { + toggle(true); + }) + .catch(err => console.log(err)); + } return ( @@ -60,7 +84,7 @@ const LinkModal = ({ modal, toggle, currentlyEdited, ...args }) => { updateField("logoUrl", e.target.value)} /> @@ -71,14 +95,14 @@ const LinkModal = ({ modal, toggle, currentlyEdited, ...args }) => { updateField("logoAlt", e.target.value)} /> - {' '}