From c2458e20c9ef54611a91aeeb2a09fb9f31660dca Mon Sep 17 00:00:00 2001 From: DamianUduevbo <58115973+DamianUduevbo@users.noreply.github.com> Date: Thu, 30 Nov 2023 12:15:18 -0500 Subject: [PATCH] implemented dropdowns for add/edit pages. styled the category tags. --- client/src/components/Admin/GiftForm.tsx | 88 +++++++++++++++++++----- client/src/components/Admin/GiftItem.tsx | 8 ++- 2 files changed, 77 insertions(+), 19 deletions(-) diff --git a/client/src/components/Admin/GiftForm.tsx b/client/src/components/Admin/GiftForm.tsx index c95f779..c8ceff8 100644 --- a/client/src/components/Admin/GiftForm.tsx +++ b/client/src/components/Admin/GiftForm.tsx @@ -23,6 +23,23 @@ const GiftForm: React.FC = ({ initialGift = defaultGift, mode, onGiftChan })); }; + // handles multiple selection input + const handleSelectChange = (e: React.ChangeEvent) => { + const { name, options } = e.target; + const values = []; + + for (let i = 0; i < options.length; i++) { + if (options[i].selected) { + values.push(options[i].value); + } + } + + setGift(prevState => ({ + ...prevState, + [name]: values, + })); + }; + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); try { @@ -32,6 +49,7 @@ const GiftForm: React.FC = ({ initialGift = defaultGift, mode, onGiftChan } if (mode === 'add') { await axios.post('/api/addGift', sentGift); + console.log("sentGift", sentGift); } else if (mode === 'edit' && gift.ID) { await axios.put(`/api/gifts/${gift.ID}`, sentGift); } @@ -82,16 +100,63 @@ const GiftForm: React.FC = ({ initialGift = defaultGift, mode, onGiftChan
- + > + + + + + + + +
+
+ + +
+
+ +
-
- - -
- + ); }; diff --git a/client/src/components/Admin/GiftItem.tsx b/client/src/components/Admin/GiftItem.tsx index c5c7d03..e760f83 100644 --- a/client/src/components/Admin/GiftItem.tsx +++ b/client/src/components/Admin/GiftItem.tsx @@ -10,6 +10,9 @@ interface GiftProps { } const GiftItem = (props: GiftProps) => { + const giftElements = props.gift?.Category?.map((category) => ( + {category} + )); return (

{props.gift.Name}

@@ -22,7 +25,10 @@ const GiftItem = (props: GiftProps) => { >Link

Demographic: {props.gift.Demographic}

-

Categories: {props.gift.Category}

+

Categories:

+
+ {giftElements} +

Description: {props.gift.Description}

Description: {props.gift.Occasion}