-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add shopLogoUrls to shop settings to allow logo to be rendered from url #5227
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1a55156
add graphql query and mutation for shopLogoUrls
kieckhafer d9a9c3b
add logo from url to ShopLogo component
kieckhafer 437f245
add admin component for shopLogoUrls
kieckhafer edd1f44
allow images from anywhere
kieckhafer e35b834
add shopLogoUrls to Shop schema
kieckhafer 5e06305
rename updateShopLogoUrls to updateShop for future expansion
kieckhafer 823d117
remove storefrontUrl mutations, move to updateShop mutation
kieckhafer 92fa606
documentation updates
kieckhafer 2d2336b
add schema validation to input
kieckhafer a9f33b0
Merge remote-tracking branch 'origin/develop' into feat-kieckhafer-ad…
kieckhafer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
imports/plugins/core/core/server/no-meteor/mutations/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import updateShopLogoUrls from "./updateShopLogoUrls"; | ||
import updateShopUrls from "./updateShopUrls"; | ||
|
||
export default { | ||
updateShopLogoUrls, | ||
updateShopUrls | ||
}; |
51 changes: 51 additions & 0 deletions
51
imports/plugins/core/core/server/no-meteor/mutations/updateShopLogoUrls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import ReactionError from "@reactioncommerce/reaction-error"; | ||
|
||
/** | ||
* @name shop/updateShopLogoUrls | ||
* @memberof Mutations/Shop | ||
* @method | ||
* @summary Add shop logo Urls to a shop | ||
* @param {Object} context - GraphQL execution context | ||
* @param {Object} input - an object of all mutation arguments that were sent | ||
* @param {String} input.shopId - The shop ID | ||
* @param {Object} input.shopLogoUrls - An object containing the Urls to update | ||
* @return {Promise<Object>} with updated shop | ||
*/ | ||
export default async function updateShopLogoUrls(context, input) { | ||
const { collections, userHasPermission } = context; | ||
const { Shops } = collections; | ||
|
||
const { | ||
shopId, | ||
shopLogoUrls | ||
} = input; | ||
|
||
|
||
// Only update provided fields inside `shopLogoUrls`, | ||
// don't update the whole object | ||
const sets = {}; | ||
Object.keys(shopLogoUrls).forEach((key) => { | ||
sets[`shopLogoUrls.${key}`] = shopLogoUrls[key]; | ||
}); | ||
|
||
// Check permission to make sure user is allowed to do this | ||
// Security check for admin access | ||
if (!userHasPermission(["owner", "admin"], shopId)) { | ||
throw new ReactionError("access-denied", "User does not have permission"); | ||
} | ||
|
||
const { value: updatedShop } = await Shops.findOneAndUpdate( | ||
{ _id: shopId }, | ||
{ | ||
$set: { | ||
...sets, | ||
updatedAt: new Date() | ||
} | ||
}, | ||
{ | ||
returnOriginal: false | ||
} | ||
); | ||
|
||
return updatedShop; | ||
} |
2 changes: 2 additions & 0 deletions
2
imports/plugins/core/core/server/no-meteor/resolvers/Mutation/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import updateShopLogoUrls from "./updateShopLogoUrls"; | ||
import updateShopUrls from "./updateShopUrls"; | ||
|
||
export default { | ||
updateShopLogoUrls, | ||
updateShopUrls | ||
}; |
33 changes: 33 additions & 0 deletions
33
imports/plugins/core/core/server/no-meteor/resolvers/Mutation/updateShopLogoUrls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { decodeShopOpaqueId } from "@reactioncommerce/reaction-graphql-xforms/shop"; | ||
|
||
/** | ||
* @name Mutation/updateShopLogoUrls | ||
* @method | ||
* @memberof Shop/GraphQL | ||
* @summary resolver for the updateShopLogoUrls GraphQL mutation | ||
* @param {Object} _ - unused | ||
* @param {Object} args.input - an object of all mutation arguments that were sent by the client | ||
* @param {String} args.input.primaryShopLogoUrl - Primariy shop logo URL | ||
* @param {Object} context - an object containing the per-request state | ||
* @return {Promise<Object>} ShopsPayload | ||
*/ | ||
export default async function updateShopLogoUrls(_, { input }, context) { | ||
const { | ||
shopId: opaqueShopId, | ||
shopLogoUrls, | ||
clientMutationId = null | ||
} = input; | ||
const shopId = decodeShopOpaqueId(opaqueShopId); | ||
|
||
const updatedShop = await context.mutations.updateShopLogoUrls(context, { | ||
shopId, | ||
shopLogoUrls | ||
}); | ||
|
||
return { | ||
shop: updatedShop, | ||
clientMutationId | ||
}; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
imports/plugins/core/dashboard/client/components/ShopLogoUrls.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import React, { Component, Fragment } from "react"; | ||
import PropTypes from "prop-types"; | ||
import gql from "graphql-tag"; | ||
import styled from "styled-components"; | ||
import { Form } from "reacto-form"; | ||
import { Mutation } from "react-apollo"; | ||
import Button from "@material-ui/core/Button"; | ||
import Card from "@material-ui/core/Card"; | ||
import CardHeader from "@material-ui/core/CardHeader"; | ||
import CardActions from "@material-ui/core/CardActions"; | ||
import CardContent from "@material-ui/core/CardContent"; | ||
import Grid from "@material-ui/core/Grid"; | ||
import ErrorsBlock from "@reactioncommerce/components/ErrorsBlock/v1"; | ||
import Field from "@reactioncommerce/components/Field/v1"; | ||
import TextInput from "@reactioncommerce/components/TextInput/v1"; | ||
import { i18next } from "/client/api"; | ||
import withPrimaryShop from "/imports/plugins/core/graphql/lib/hocs/withPrimaryShop"; | ||
|
||
const PaddedField = styled(Field)` | ||
margin-bottom: 30px; | ||
`; | ||
|
||
const RightAlignedGrid = styled(Grid)` | ||
text-align: right; | ||
`; | ||
|
||
const updateShopUrlsMutation = gql` | ||
mutation updateShopLogoUrlsMutation($input: UpdateShopLogoUrlsInput!) { | ||
updateShopLogoUrls(input: $input) { | ||
clientMutationId | ||
shop { | ||
_id | ||
shopLogoUrls { | ||
primaryShopLogoUrl | ||
} | ||
} | ||
} | ||
} | ||
`; | ||
|
||
class ShopLogoUrls extends Component { | ||
static propTypes = { | ||
shop: PropTypes.shape({ | ||
shopLogoUrls: PropTypes.shape({ | ||
primaryShopLogoUrl: PropTypes.string | ||
}) | ||
}) | ||
}; | ||
|
||
handleFormChange = (value) => { | ||
this.formValue = value; | ||
}; | ||
|
||
handleSubmitForm = () => { | ||
this.form.submit(); | ||
}; | ||
|
||
handleUpdateUrls(data, mutation) { | ||
const { | ||
shop: { _id: shopId } | ||
} = this.props; | ||
const { primaryShopLogoUrl } = data; | ||
|
||
// return null; | ||
mutation({ | ||
variables: { | ||
input: { | ||
shopId, | ||
shopLogoUrls: { | ||
primaryShopLogoUrl | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
render() { | ||
const { shop } = this.props; | ||
const { shopLogoUrls } = shop; | ||
const { primaryShopLogoUrl } = shopLogoUrls || {}; | ||
|
||
console.log("shop", shop); | ||
console.log("shopLogoUrls", shopLogoUrls); | ||
console.log("primaryShopLogoUrl", primaryShopLogoUrl); | ||
|
||
|
||
return ( | ||
<Card> | ||
<CardHeader | ||
subheader={i18next.t( | ||
"shopSettings.shopLogoUrls.description", | ||
"Use these fields to provide URL's for static image files to use as store logos. These URL's will override any logos uploaded." | ||
)} | ||
title={i18next.t("shopSettings.shopLogoUrls.title", "Shop Logo Urls")} | ||
/> | ||
<Mutation mutation={updateShopUrlsMutation}> | ||
{(mutationFunc) => ( | ||
<Fragment> | ||
<Form | ||
ref={(formRef) => { | ||
this.form = formRef; | ||
}} | ||
onChange={this.handleFormChange} | ||
onSubmit={(data) => this.handleUpdateUrls(data, mutationFunc)} | ||
value={shop} | ||
> | ||
<CardContent> | ||
<PaddedField | ||
name="primaryShopLogoUrl" | ||
label={i18next.t("shopSettings.shopLogoUrls.primaryShopLogoUrlTitle", "Primary Shop Logo")} | ||
labelFor="primaryShopLogoUrlInput" | ||
> | ||
<TextInput | ||
id="primaryShopLogoUrlInput" | ||
name="primaryShopLogoUrl" | ||
placeholder={i18next.t("shopSettings.shopLogoUrls.primaryShopLogoUrlDescription", "This is the primary shop logo, which is used wherever you see a logo throughout the UI")} | ||
value={primaryShopLogoUrl || ""} | ||
/> | ||
<ErrorsBlock names={["primaryShopLogoUrl"]} /> | ||
</PaddedField> | ||
</CardContent> | ||
<CardActions> | ||
<Grid container alignItems="center" justify="flex-end"> | ||
<RightAlignedGrid item xs={12}> | ||
<Button color="primary" variant="contained" onClick={this.handleSubmitForm}> | ||
{i18next.t("app.save")} | ||
</Button> | ||
</RightAlignedGrid> | ||
</Grid> | ||
</CardActions> | ||
</Form> | ||
</Fragment> | ||
)} | ||
</Mutation> | ||
</Card> | ||
); | ||
} | ||
} | ||
|
||
export default withPrimaryShop(ShopLogoUrls); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this being used anywhere. Should the field just be added to shop schema?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.