Skip to content

Commit

Permalink
Change solution
Browse files Browse the repository at this point in the history
  • Loading branch information
bivillar committed Apr 2, 2020
1 parent d93f99f commit 0615dcb
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions react/components/Profile/NewsletterBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ const messages = defineMessages({
})

class NewsletterBox extends Component<Props, State> {
public state = {
checked: false,
public constructor(props: Props) {
super(props)
this.state = {
checked: props.isNewsletterOptIn,
}
}

public componentDidUpdate(oldProps: Props) {
Expand All @@ -48,7 +51,7 @@ class NewsletterBox extends Component<Props, State> {
isNewsletterOptIn: !checked,
},
}),
1000
500
)
this.setState({ checked: !checked })
}
Expand Down Expand Up @@ -91,11 +94,9 @@ interface ExternalProps {

interface QueryData {
profile: Pick<Profile, 'customFields'>
loading: boolean
}

interface QueryResult {
loading?: boolean
isNewsletterOptIn: boolean
}

Expand All @@ -106,15 +107,15 @@ interface Mutations {
const enhance = compose<Props, ExternalProps>(
graphql<Props, QueryData, unknown, QueryResult>(GET_NEWSLETTER, {
props: ({ data }) => ({
isNewsletterOptIn:
data?.profile?.customFields?.[0].value.toLowerCase() === 'true',
loading: data?.loading,
isNewsletterOptIn: data?.profile?.customFields?.[0].value === 'true',
}),
}),
graphql(NEWSLETTER_MUTATION, {
name: 'setOptInNewsletter',
options: {
fetchPolicy: 'cache-and-network',
refetchQueries: ['NewsletterOpt'],
},
}),
graphql(NEWSLETTER_MUTATION, { name: 'setOptInNewsletter' }),
injectIntl
)

Expand Down

0 comments on commit 0615dcb

Please sign in to comment.