Subscribe.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {
  2. actionFullUnSubscribe,
  3. actionFullSubscribe,
  4. } from '../actions'
  5. import { Button} from 'antd'
  6. import { connect } from 'react-redux'
  7. const Subscribe = ({
  8. my_Id,
  9. deleteSubscribe,
  10. aboutMeFollowing = [],
  11. addSubscribe,
  12. followId,
  13. }) => {
  14. const checkFollowId = aboutMeFollowing?.find(
  15. (follower) => follower?._id === followId,
  16. )?._id
  17. return (
  18. <>
  19. <div style={{ display: 'flex' }}>
  20. {checkFollowId ? (
  21. <Button
  22. size="large" type="primary"
  23. danger
  24. onClick={() => deleteSubscribe(my_Id, followId)}
  25. >
  26. Unsubscribe
  27. </Button>
  28. ) : (
  29. <Button
  30. size="large"
  31. type="primary"
  32. primary
  33. onClick={() => addSubscribe(my_Id, followId)}
  34. >
  35. Subscribe
  36. </Button>
  37. )}
  38. </div>
  39. </>
  40. )
  41. }
  42. export const CSubscribe = connect((state) => ({
  43. my_Id: state.auth?.payload?.sub?.id,
  44. aboutMeFollowing: state.myData?.aboutMe?.following,
  45. followId: state.userData?.aboutUser?._id,
  46. }),
  47. {
  48. addSubscribe: actionFullSubscribe,
  49. deleteSubscribe: actionFullUnSubscribe,
  50. }
  51. )(Subscribe)