@graphcommerce/magento-newsletter 2.1.7 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # Change Log
2
2
 
3
+ ## 2.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1645](https://github.com/graphcommerce-org/graphcommerce/pull/1645) [`f0ddcb868`](https://github.com/graphcommerce-org/graphcommerce/commit/f0ddcb86815d0525842c79a168c08e99f5799c76) Thanks [@Jessevdpoel](https://github.com/Jessevdpoel)! - Added Subscribe to newsletter checkbox
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [[`42e7fac75`](https://github.com/graphcommerce-org/graphcommerce/commit/42e7fac75712f9bda7a6b919ede14b3c75d07771)]:
12
+ - @graphcommerce/next-ui@4.26.0
13
+ - @graphcommerce/magento-cart@4.8.3
14
+ - @graphcommerce/magento-customer@4.11.3
15
+
16
+ ## 2.1.8
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [[`dc6237644`](https://github.com/graphcommerce-org/graphcommerce/commit/dc6237644ac349debb728059e4c937cec25bf4fd), [`48273bccd`](https://github.com/graphcommerce-org/graphcommerce/commit/48273bccd2e471ce4bc024a600e693da791f1cde)]:
21
+ - @graphcommerce/next-ui@4.25.0
22
+ - @graphcommerce/magento-cart@4.8.2
23
+ - @graphcommerce/magento-customer@4.11.2
24
+
3
25
  ## 2.1.7
4
26
 
5
27
  ### Patch Changes
@@ -0,0 +1,57 @@
1
+ import { CheckboxElement, useFormCompose } from '@graphcommerce/ecommerce-ui'
2
+ import { DocumentNode } from '@graphcommerce/graphql'
3
+ import { useCartQuery } from '@graphcommerce/magento-cart'
4
+ import { useCustomerQuery, useCustomerSession } from '@graphcommerce/magento-customer'
5
+ import { useFormGql, useFormGqlMutation } from '@graphcommerce/react-hook-form'
6
+ import { Box, SxProps, Theme } from '@mui/material'
7
+ import { GetCustomerNewsletterToggleDocument } from '../CustomerNewsletterToggle/GetCustomerNewsLetterToggle.gql'
8
+ import { GetCartEmailDocument } from '../SignupNewsletter/GetCartEmail.gql'
9
+ import { SubscribeCustomerDocument } from './SubscribeCustomer.gql'
10
+ import {
11
+ SubscribeGuestDocument,
12
+ SubscribeGuestMutation,
13
+ SubscribeGuestMutationVariables,
14
+ } from './SubscribeGuest.gql'
15
+
16
+ type CheckoutNewsletterProps = {
17
+ step: number
18
+ checked?: boolean
19
+ label: string
20
+ sx?: SxProps<Theme>
21
+ }
22
+
23
+ export function SubscribeToNewsletter(props: CheckoutNewsletterProps) {
24
+ const { step, checked = false, label, sx } = props
25
+ const cartEmail = useCartQuery(GetCartEmailDocument).data?.cart?.email
26
+
27
+ const { loggedIn } = useCustomerSession()
28
+ const isCustomerSubscribed = useCustomerQuery(GetCustomerNewsletterToggleDocument).data?.customer
29
+ ?.is_subscribed
30
+
31
+ const form = useFormGqlMutation<
32
+ SubscribeGuestMutation,
33
+ SubscribeGuestMutationVariables & { subscribe: boolean }
34
+ >(
35
+ loggedIn ? (SubscribeCustomerDocument as DocumentNode) : SubscribeGuestDocument,
36
+ {
37
+ defaultValues: { subscribe: checked },
38
+ onBeforeSubmit: ({ subscribe }) =>
39
+ subscribe ? { subscribe, email: cartEmail ?? '' } : false,
40
+ },
41
+ { errorPolicy: 'all' },
42
+ )
43
+ const { control, handleSubmit } = form
44
+ const submit = handleSubmit(() => {})
45
+
46
+ useFormCompose({ form, step, submit, key: 'NewsletterSubscribeForm' })
47
+
48
+ if (isCustomerSubscribed) return null
49
+
50
+ return (
51
+ <Box sx={sx}>
52
+ <form onSubmit={submit} noValidate>
53
+ <CheckboxElement color='secondary' control={control} name='subscribe' label={label} />
54
+ </form>
55
+ </Box>
56
+ )
57
+ }
@@ -0,0 +1,7 @@
1
+ mutation SubscribeCustomer {
2
+ updateCustomer(input: { is_subscribed: true }) {
3
+ customer {
4
+ is_subscribed
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,5 @@
1
+ mutation SubscribeGuest($email: String!) {
2
+ subscribeEmailToNewsletter(email: $email) {
3
+ status
4
+ }
5
+ }
@@ -1,2 +1,3 @@
1
1
  export * from './CustomerNewsletterToggle/CustomerNewsletterToggle'
2
2
  export * from './SignupNewsletter/SignupNewsletter'
3
+ export * from './CheckoutNewsletter/CheckoutNewsletter'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-newsletter",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "2.1.7",
5
+ "version": "2.2.0",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -19,9 +19,9 @@
19
19
  },
20
20
  "dependencies": {
21
21
  "@graphcommerce/graphql": "3.4.8",
22
- "@graphcommerce/magento-cart": "4.8.1",
23
- "@graphcommerce/magento-customer": "4.11.1",
24
- "@graphcommerce/next-ui": "4.24.0",
22
+ "@graphcommerce/magento-cart": "4.8.3",
23
+ "@graphcommerce/magento-customer": "4.11.3",
24
+ "@graphcommerce/next-ui": "4.26.0",
25
25
  "@graphcommerce/react-hook-form": "3.3.3"
26
26
  },
27
27
  "peerDependencies": {