Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
duyphan
shopify-theme
Commits
1efc2334
Commit
1efc2334
authored
4 years ago
by
duyphan
Browse files
Options
Download
Email Patches
Plain Diff
feat(app/get_started): created graphql mutation
parent
70f8058a
master
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
apps/get_started/components/GraphQLMutation.js
+34
-0
apps/get_started/components/GraphQLMutation.js
apps/get_started/pages/banner-config.js
+36
-18
apps/get_started/pages/banner-config.js
apps/get_started/services/theme/index.js
+3
-0
apps/get_started/services/theme/index.js
apps/get_started/services/theme/queries.js
+15
-0
apps/get_started/services/theme/queries.js
with
88 additions
and
18 deletions
+88
-18
apps/get_started/components/GraphQLMutation.js
0 → 100644
View file @
1efc2334
import
{
useState
}
from
"
react
"
;
import
{
Mutation
}
from
"
react-apollo
"
;
import
{
Frame
,
Banner
,
Toast
}
from
"
@shopify/polaris
"
;
export
const
GraphQLMutation
=
({
children
,
query
})
=>
{
return
(
<
Mutation
mutation
=
{
query
}
>
{(
handleSubmit
,
response
)
=>
{
const
{
error
,
data
}
=
response
;
let
showError
;
let
showToast
;
if
(
error
)
{
showError
=
error
&&
(
<
Banner
status
=
"
critical
"
>
{
error
.
message
}
<
/Banner
>
);
}
else
if
(
data
)
{
showToast
=
<
Toast
content
=
"
Sucessfully updated
"
duration
=
{
1000
}
/>
;
}
return
(
<
Frame
>
{
children
({
handleSubmit
,
response
,
showError
,
showToast
,
})}
<
/Frame
>
);
}}
<
/Mutation
>
);
};
This diff is collapsed.
Click to expand it.
apps/get_started/pages/banner-config.js
View file @
1efc2334
import
{
useState
,
useCallback
}
from
"
react
"
;
import
{
Layout
,
Page
,
AccountConnection
,
Link
}
from
"
@shopify/polaris
"
;
import
{
GraphQLMutation
}
from
"
../components/GraphQLMutation
"
;
import
{
CREATE_SCRIPT_TAG
}
from
"
../services/theme
"
;
const
BannerConfig
=
()
=>
{
const
[
connected
,
setConnected
]
=
useState
(
false
);
const
accountName
=
connected
?
"
Jane Appleseed
"
:
""
;
const
handleAction
=
useCallback
(()
=>
{
setConnected
((
connected
)
=>
!
connected
);
},
[
connected
]);
const
handleAction
=
useCallback
(
(
handleSubmit
)
=>
{
setConnected
((
connected
)
=>
!
connected
);
handleSubmit
({
variables
:
{
input
:
{
src
:
"
https://www.google.com/
"
},
},
});
},
[
connected
]
);
const
buttonText
=
connected
?
"
Disable
"
:
"
Enable
"
;
const
details
=
connected
?
"
Active
"
:
"
Inactive
"
;
...
...
@@ -19,21 +29,29 @@ const BannerConfig = () => {
);
return
(
<
Page
>
<
Layout
.
Section
>
<
AccountConnection
accountName
=
{
accountName
}
connected
=
{
connected
}
title
=
"
Banner Configuration
"
action
=
{{
content
:
buttonText
,
onAction
:
handleAction
,
}}
details
=
{
details
}
termsOfService
=
{
terms
}
/
>
<
/Layout.Section
>
<
/Page
>
<
GraphQLMutation
query
=
{
CREATE_SCRIPT_TAG
}
>
{({
handleSubmit
,
showError
,
showToast
})
=>
{
return
(
<
Page
>
<
Layout
.
Section
>
{
showError
}
{
showToast
}
<
AccountConnection
accountName
=
{
accountName
}
connected
=
{
connected
}
title
=
"
Banner Configurations
"
action
=
{{
content
:
buttonText
,
onAction
:
()
=>
handleAction
(
handleSubmit
),
}}
details
=
{
details
}
termsOfService
=
{
terms
}
/
>
<
/Layout.Section
>
<
/Page
>
);
}}
<
/GraphQLMutation
>
);
};
export
default
BannerConfig
;
This diff is collapsed.
Click to expand it.
apps/get_started/services/theme/index.js
0 → 100644
View file @
1efc2334
import
{
CREATE_SCRIPT_TAG
}
from
"
./queries
"
;
export
{
CREATE_SCRIPT_TAG
};
This diff is collapsed.
Click to expand it.
apps/get_started/services/theme/queries.js
0 → 100644
View file @
1efc2334
import
gql
from
"
graphql-tag
"
;
export
const
CREATE_SCRIPT_TAG
=
gql
`
mutation scriptTagCreate($input: ScriptTagInput!) {
scriptTagCreate(input: $input) {
scriptTag {
id
}
userErrors {
field
message
}
}
}
`
;
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help