Skip to content

Commit

Permalink
Merge pull request #319 from ita-social-projects/#304-EliminateAbilit…
Browse files Browse the repository at this point in the history
…yAddOwnCompanyToSaved

Add to saved button hidden for profile owner
  • Loading branch information
Lvyshnevska authored Nov 20, 2023
2 parents 02fb084 + 6bb2bdf commit 848e534
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions FrontEnd/src/components/ProfileDetail/MainInfo/TitleInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ function TitleInfo({ isAuthorized, data }) {
};
}, [data]);

const ownProfile = user && user.id === profile.personId;

async function sendRequest(url, { arg: data }) {
const authToken = localStorage.getItem('Token');
return fetch(url, {
Expand Down Expand Up @@ -61,9 +63,8 @@ function TitleInfo({ isAuthorized, data }) {
await trigger(
{ company_pk: profile.id },
{ optimisticData: () => {
if (user.id !== profile.personId)
{setIsSaved(!isSaved);
}}
setIsSaved(!isSaved);
}
}
);
} catch (error) {
Expand Down Expand Up @@ -132,15 +133,16 @@ function TitleInfo({ isAuthorized, data }) {
</div>
<div className={classes['title-block__company_region']}>{profile.region}</div>
</div>
{isAuthorized && (
<button
onClick={handleClick}
type="button"
className={`${classes['title-block__button']} ${isSaved && classes['added_to_saved__button']}`}
>
<span className={`${classes['title-block__button--text']} ${isSaved && classes['added_to_saved__button--text']}`}>{!isSaved ? 'Додати в збережені' : 'Додано в збережені'}</span>
{isAuthorized ? (isSaved ? filledStar : outlinedStar) : null}
</button>)}
{isAuthorized && !ownProfile ? (
<button
onClick={handleClick}
type="button"
className={`${classes['title-block__button']} ${isSaved && classes['added_to_saved__button']}`}
>
<span className={`${classes['title-block__button--text']} ${isSaved && classes['added_to_saved__button--text']}`}>{!isSaved ? 'Додати в збережені' : 'Додано в збережені'}</span>
{isAuthorized ? (isSaved ? filledStar : outlinedStar) : null}
</button>
) : null}
</div>
);
}
Expand Down

0 comments on commit 848e534

Please sign in to comment.