-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3049 from reactioncommerce/mm-shop-manager-2864
Adds the ability to set shops to active / disabled
- Loading branch information
Showing
17 changed files
with
339 additions
and
31 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
imports/plugins/included/default-theme/client/styles/dashboard/tables.less
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,39 @@ | ||
.rui.sortable-table-container { | ||
position: relative; | ||
padding: 20px; | ||
} | ||
|
||
.sortable-table .title { | ||
text-transform: capitalize; | ||
} | ||
|
||
.sortable-table .col-dropdown, | ||
.sortable-table .col-button { | ||
width: 100%; | ||
font-weight: @badge-font-weight; | ||
display: inherit; | ||
text-align: center; | ||
} | ||
|
||
.sortable-table .rt-td span { | ||
line-height: 2; | ||
} | ||
|
||
.sortable-table .-odd { | ||
background: transparent; | ||
} | ||
|
||
.sortable-table .rt-td .btn { | ||
padding: 0 5%; | ||
width: 80%; | ||
} | ||
|
||
.sortable-table .rt-thead.-header .rt-th { | ||
text-align: left; | ||
margin-left: 20px; | ||
line-height: 2; | ||
} | ||
|
||
.sortable-table .rt-tr-group:last-child { | ||
border-bottom: 1px solid @rui-default-disabled; | ||
} |
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/included/marketplace/client/components/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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as MarketplaceShops } from "./marketplaceShops"; | ||
export { default as MarketplaceShopTableCell } from "./marketplaceShopTableCell"; |
83 changes: 83 additions & 0 deletions
83
imports/plugins/included/marketplace/client/components/marketplaceShopTableCell.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,83 @@ | ||
import _ from "lodash"; | ||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { Components, registerComponent } from "@reactioncommerce/reaction-components"; | ||
import { SHOP_WORKFLOW_STATUS_ACTIVE, SHOP_WORKFLOW_STATUS_DISABLED } from "../../lib/constants"; | ||
|
||
class MarketplaceShopTableCell extends Component { | ||
static propTypes = { | ||
data: PropTypes.object, | ||
field: PropTypes.string, | ||
onWorkflowChange: PropTypes.func | ||
} | ||
|
||
get shop() { | ||
return this.props.data.original; | ||
} | ||
|
||
get status() { | ||
if (this.shop.workflow) { | ||
return this.shop.workflow.status; | ||
} | ||
|
||
return SHOP_WORKFLOW_STATUS_ACTIVE; | ||
} | ||
|
||
handleWorkflowChange = (event, value) => { | ||
if (this.props.onWorkflowChange) { | ||
// Get the shop id from the original document | ||
const { _id } = this.shop; | ||
|
||
this.props.onWorkflowChange(_id, value); | ||
} | ||
} | ||
|
||
render() { | ||
const { field, data } = this.props; | ||
|
||
if (field === "emails" && Array.isArray(data.value) && data.value.length) { | ||
return ( | ||
<div className="table-cell body"> | ||
<span>{data.value[0].address}</span> | ||
</div> | ||
); | ||
} | ||
|
||
if (field === "workflow") { | ||
return ( | ||
<Components.DropDownMenu | ||
buttonElement={ | ||
<div className="col-dropdown"> | ||
<Components.Button bezelStyle="solid" label={_.startCase(this.status)}> | ||
| ||
<i className="fa fa-chevron-down" /> | ||
</Components.Button> | ||
</div> | ||
} | ||
onChange={this.handleWorkflowChange} | ||
value={this.status} | ||
> | ||
<Components.MenuItem | ||
label="Active" | ||
value={SHOP_WORKFLOW_STATUS_ACTIVE} | ||
/> | ||
<Components.MenuItem | ||
label="Disabled" | ||
value={SHOP_WORKFLOW_STATUS_DISABLED} | ||
/> | ||
</Components.DropDownMenu> | ||
); | ||
} | ||
|
||
|
||
return ( | ||
<div className="table-cell body"> | ||
<span>{data.value}</span> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
registerComponent("MarketplaceShopTableCell", MarketplaceShopTableCell); | ||
|
||
export default MarketplaceShopTableCell; |
51 changes: 51 additions & 0 deletions
51
imports/plugins/included/marketplace/client/components/marketplaceShops.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 React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { Components } from "@reactioncommerce/reaction-components"; | ||
|
||
class MarketplaceShops extends Component { | ||
static propTypes = { | ||
onWorkflowChange: PropTypes.func, | ||
shops: PropTypes.arrayOf(PropTypes.object) | ||
} | ||
|
||
renderShopsTable() { | ||
const fields = ["name", "emails", "workflow"]; | ||
|
||
const columnMetadata = fields.map((field) => { | ||
return { | ||
Header: <Components.Translation i18nKey={`marketplaceShops.headers.${field}`} defaultValue={field} />, | ||
accessor: field, | ||
Cell: (data) => ( | ||
<Components.MarketplaceShopTableCell | ||
data={data} | ||
field={field} | ||
onWorkflowChange={this.props.onWorkflowChange} | ||
/> | ||
) | ||
}; | ||
}); | ||
|
||
return ( | ||
<Components.SortableTable | ||
data={this.props.shops} | ||
columnMetadata={columnMetadata} | ||
filteredFields={fields} | ||
filterType="none" | ||
showFilter={true} | ||
isSortable={false} | ||
/> | ||
); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="rui sortable-table-container"> | ||
<div className="rui sortable-table"> | ||
{this.renderShopsTable()} | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default MarketplaceShops; |
1 change: 1 addition & 0 deletions
1
imports/plugins/included/marketplace/client/containers/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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as MarketplaceShopsContainer } from "./marketplaceShops"; |
27 changes: 27 additions & 0 deletions
27
imports/plugins/included/marketplace/client/containers/marketplaceShops.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,27 @@ | ||
import { composeWithTracker, registerComponent } from "@reactioncommerce/reaction-components"; | ||
import { Meteor } from "meteor/meteor"; | ||
import { Shops } from "/lib/collections"; | ||
import { Reaction } from "/client/api"; | ||
import MarketplaceShops from "../components/marketplaceShops"; | ||
|
||
const onWorkflowChange = (shopId, value) => { | ||
Meteor.call("marketplace/updateShopWorkflow", shopId, value); | ||
}; | ||
|
||
const composer = (props, onData) => { | ||
// Get all shops, excluding the primary shop | ||
const shops = Shops.find({ | ||
_id: { | ||
$nin: [Reaction.getPrimaryShopId()] | ||
} | ||
}).fetch(); | ||
|
||
onData(null, { | ||
shops, | ||
onWorkflowChange | ||
}); | ||
}; | ||
|
||
registerComponent("MarketplaceShops", MarketplaceShops, composeWithTracker(composer)); | ||
|
||
export default composeWithTracker(composer)(MarketplaceShops); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
export const SHOP_WORKFLOW_STATUS_ACTIVE = "active"; | ||
export const SHOP_WORKFLOW_STATUS_DISABLED = "disabled"; | ||
export const SHOP_WORKFLOW_STATUS_ARCHIVED = "archived"; |
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
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,10 +1,33 @@ | ||
import { loadTranslations } from "/server/startup/i18n"; | ||
|
||
import ar from "./ar.json"; | ||
import bg from "./bg.json"; | ||
import cs from "./cs.json"; | ||
import de from "./de.json"; | ||
import el from "./el.json"; | ||
import en from "./en.json"; | ||
import es from "./es.json"; | ||
import fr from "./fr.json"; | ||
import he from "./he.json"; | ||
import hr from "./hr.json"; | ||
import hu from "./hu.json"; | ||
import it from "./it.json"; | ||
import my from "./my.json"; | ||
import nb from "./nb.json"; | ||
import nl from "./nl.json"; | ||
import pl from "./pl.json"; | ||
import pt from "./pt.json"; | ||
import ro from "./ro.json"; | ||
import ru from "./ru.json"; | ||
import sl from "./sl.json"; | ||
import sv from "./sv.json"; | ||
import tr from "./tr.json"; | ||
import vi from "./vi.json"; | ||
import zh from "./zh.json"; | ||
|
||
// | ||
// we want all the files in individual | ||
// imports for easier handling by | ||
// automated translation software | ||
// | ||
loadTranslations([en]); | ||
loadTranslations([ar, bg, cs, de, el, en, es, fr, he, hr, hu, it, my, nb, nl, pl, pt, ro, ru, sl, sv, tr, vi, zh]); |
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,2 +1,3 @@ | ||
import "./methods.js"; | ||
import "./i18n"; | ||
import "./publications.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,23 +1,43 @@ | ||
// import { Meteor } from "meteor/meteor"; | ||
// // import { check } from "meteor/check"; | ||
// // import { Reaction } from "/lib/api"; | ||
// // import { Shops } from "/lib/collections"; | ||
// | ||
// | ||
// Meteor.methods({ | ||
// // "marketplace/updateShopDetails": function (doc, _id) { | ||
// // check(_id, String); | ||
// // check(doc, Object); | ||
// // | ||
// // if (!Reaction.hasPermission("admin", this.userId, Reaction.getSellerShopId(this.userId))) { | ||
// // return; | ||
// // } | ||
// // | ||
// // Shops.update(_id, doc, function (error) { | ||
// // if (error) { | ||
// // throw new Meteor.Error(500, error.message); | ||
// // } | ||
// // }); | ||
// // } | ||
// // | ||
// }); | ||
import { Meteor } from "meteor/meteor"; | ||
import { check } from "meteor/check"; | ||
import { Reaction } from "/lib/api"; | ||
import { Shops } from "/lib/collections"; | ||
import { SHOP_WORKFLOW_STATUS_ACTIVE, SHOP_WORKFLOW_STATUS_DISABLED } from "../lib/constants"; | ||
|
||
const status = [ | ||
SHOP_WORKFLOW_STATUS_ACTIVE, | ||
SHOP_WORKFLOW_STATUS_DISABLED | ||
]; | ||
|
||
export function marketplaceUpdateShopWorkflow(shopId, workflowStatus) { | ||
check(shopId, String); | ||
check(workflowStatus, String); | ||
|
||
if (shopId === Reaction.getPrimaryShopId()) { | ||
throw new Meteor.Error("access-denied", "Cannot change shop status"); | ||
} | ||
|
||
if (!Reaction.hasPermission("admin", this.userId, Reaction.getPrimaryShopId())) { | ||
throw new Meteor.Error("access-denied", "Cannot change shop status"); | ||
} | ||
|
||
if (status.includes(workflowStatus)) { | ||
return Shops.update({ | ||
_id: shopId | ||
}, { | ||
$set: { | ||
"workflow.status": workflowStatus | ||
} | ||
}, function (error) { | ||
if (error) { | ||
throw new Meteor.Error("server-error", error.message); | ||
} | ||
}); | ||
} | ||
|
||
throw new Meteor.Error("server-error", "Workflow status could not be updated, should be 'active' or 'disabled'"); | ||
} | ||
|
||
Meteor.methods({ | ||
"marketplace/updateShopWorkflow": marketplaceUpdateShopWorkflow | ||
}); |
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.