Subscribe.jsx 1.3 KB

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