diff --git a/components/BeerById/BeerInfoHeader.tsx b/components/BeerById/BeerInfoHeader.tsx index 49f970b..8f59674 100644 --- a/components/BeerById/BeerInfoHeader.tsx +++ b/components/BeerById/BeerInfoHeader.tsx @@ -5,6 +5,7 @@ import { FC, useContext, useEffect, useState } from 'react'; import { BeerPostQueryResult } from '@/services/BeerPost/schema/BeerPostQueryResult'; import UserContext from '@/contexts/userContext'; +import { FaRegEdit } from 'react-icons/fa'; import BeerPostLikeButton from './BeerPostLikeButton'; const BeerInfoHeader: FC<{ beerPost: BeerPostQueryResult; initialLikeCount: number }> = ({ @@ -16,6 +17,18 @@ const BeerInfoHeader: FC<{ beerPost: BeerPostQueryResult; initialLikeCount: numb const { user } = useContext(UserContext); const [likeCount, setLikeCount] = useState(initialLikeCount); + const [isPostOwner, setIsPostOwner] = useState(false); + + useEffect(() => { + const idMatches = user && beerPost.postedBy.id === user.id; + + if (!(user && idMatches)) { + setIsPostOwner(false); + return; + } + + setIsPostOwner(true); + }, [user, beerPost]); useEffect(() => { setLikeCount(initialLikeCount); @@ -28,16 +41,31 @@ const BeerInfoHeader: FC<{ beerPost: BeerPostQueryResult; initialLikeCount: numb return (
-

{beerPost.name}

-

- by{' '} - - {beerPost.brewery.name} - -

+
+
+

{beerPost.name}

+

+ by{' '} + + {beerPost.brewery.name} + +

+
+
+ {isPostOwner && ( + + + Edit + + )} +
+

posted by{' '} @@ -53,7 +81,7 @@ const BeerInfoHeader: FC<{ beerPost: BeerPostQueryResult; initialLikeCount: numb

{beerPost.description}

-
+
= ({ /> - - Type - {errors.typeId?.message} - - - ({ - value: beerType.id, - text: beerType.name, - }))} - placeholder="Beer type" - message="Pick a beer type" - /> - + {formType === 'create' && types.length && ( + <> + + Type + {errors.typeId?.message} + + + ({ + value: beerType.id, + text: beerType.name, + }))} + placeholder="Beer type" + message="Pick a beer type" + /> + + + )} {!isSubmitting && (