-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 #599 from evershopcommerce/dev
Dev
- Loading branch information
Showing
130 changed files
with
4,629 additions
and
211 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
28 changes: 28 additions & 0 deletions
28
packages/evershop/src/components/admin/cms/widget/WidgetTypes.jsx
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,28 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
export default function WidgetTypes({ types }) { | ||
return ( | ||
<div className="grid grid-cols-3 gap-4"> | ||
{types.map((type) => ( | ||
<a | ||
key={type.code} | ||
href={type.createWidgetUrl} | ||
className="border border-gray-200 rounded p-4 text-center" | ||
> | ||
<div className="text-lg font-bold">{type.name}</div> | ||
</a> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
WidgetTypes.propTypes = { | ||
types: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
code: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired, | ||
createWidgetUrl: PropTypes.string.isRequired | ||
}) | ||
).isRequired | ||
}; |
29 changes: 29 additions & 0 deletions
29
packages/evershop/src/components/admin/cms/widget/grid/WidgetTypeRow.jsx
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,29 @@ | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
|
||
export default function WidgetTypeRow({ code, types }) { | ||
const type = types.find((t) => t.code === code); | ||
if (!type) { | ||
return ( | ||
<td> | ||
<div>Unknown</div> | ||
</td> | ||
); | ||
} else { | ||
return ( | ||
<td> | ||
<div>{type.name}</div> | ||
</td> | ||
); | ||
} | ||
} | ||
|
||
WidgetTypeRow.propTypes = { | ||
code: PropTypes.string.isRequired, | ||
types: PropTypes.arrayOf( | ||
PropTypes.shape({ | ||
code: PropTypes.string.isRequired, | ||
name: PropTypes.string.isRequired | ||
}) | ||
).isRequired | ||
}; |
203 changes: 203 additions & 0 deletions
203
packages/evershop/src/components/admin/widgets/CollectionProductsSetting.jsx
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,203 @@ | ||
import { Card } from '@components/admin/cms/Card'; | ||
import Spinner from '@components/common/Spinner'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import { useQuery } from 'urql'; | ||
import CheckIcon from '@heroicons/react/outline/CheckIcon'; | ||
import { SimplePageination } from '@components/common/SimplePagination'; | ||
import { Field } from '@components/common/form/Field'; | ||
|
||
const SearchQuery = ` | ||
query Query ($filters: [FilterInput!]) { | ||
collections(filters: $filters) { | ||
items { | ||
collectionId | ||
uuid | ||
code | ||
name | ||
} | ||
total | ||
} | ||
} | ||
`; | ||
|
||
function CollectionProductsSetting({ | ||
collectionProductsWidget: { collection, count } | ||
}) { | ||
const limit = 10; | ||
const [inputValue, setInputValue] = React.useState(null); | ||
const [selectedCollection, setSelectedCollection] = | ||
React.useState(collection); | ||
const [page, setPage] = React.useState(1); | ||
|
||
const [result, reexecuteQuery] = useQuery({ | ||
query: SearchQuery, | ||
variables: { | ||
filters: inputValue | ||
? [ | ||
{ key: 'name', operation: 'like', value: inputValue }, | ||
{ key: 'page', operation: 'eq', value: page.toString() }, | ||
{ key: 'limit', operation: 'eq', value: limit.toString() } | ||
] | ||
: [ | ||
{ key: 'limit', operation: 'eq', value: limit.toString() }, | ||
{ key: 'page', operation: 'eq', value: page.toString() } | ||
] | ||
}, | ||
pause: true | ||
}); | ||
|
||
React.useEffect(() => { | ||
reexecuteQuery({ requestPolicy: 'network-only' }); | ||
}, []); | ||
|
||
React.useEffect(() => { | ||
const timer = setTimeout(() => { | ||
if (inputValue !== null) { | ||
reexecuteQuery({ requestPolicy: 'network-only' }); | ||
} | ||
}, 1500); | ||
|
||
return () => clearTimeout(timer); | ||
}, [inputValue]); | ||
|
||
React.useEffect(() => { | ||
reexecuteQuery({ requestPolicy: 'network-only' }); | ||
}, [page]); | ||
|
||
const { data, fetching, error } = result; | ||
|
||
if (error) { | ||
return ( | ||
<p> | ||
There was an error fetching collections. | ||
{error.message} | ||
</p> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
<div className="modal-content"> | ||
<Card.Session title="Select a collection"> | ||
<div> | ||
<div className="border rounded border-divider mb-8"> | ||
<input | ||
type="text" | ||
value={inputValue} | ||
placeholder="Search collections" | ||
onChange={(e) => setInputValue(e.target.value)} | ||
/> | ||
<Field | ||
type="hidden" | ||
name="settings[collection]" | ||
value={selectedCollection} | ||
validationRules={['notEmpty']} | ||
/> | ||
</div> | ||
{fetching && ( | ||
<div className="p-3 border border-divider rounded flex justify-center items-center"> | ||
<Spinner width={25} height={25} /> | ||
</div> | ||
)} | ||
{!fetching && data && ( | ||
<div className="divide-y"> | ||
{data.collections.items.length === 0 && ( | ||
<div className="p-3 border border-divider rounded flex justify-center items-center"> | ||
{inputValue ? ( | ||
<p> | ||
No collections found for query "{inputValue}” | ||
</p> | ||
) : ( | ||
<p>You have no collections to display</p> | ||
)} | ||
</div> | ||
)} | ||
{data.collections.items.map((collection) => ( | ||
<div | ||
key={collection.uuid} | ||
className="grid grid-cols-8 gap-8 py-4 border-divider items-center" | ||
> | ||
<div className="col-span-6"> | ||
<h3>{collection.name}</h3> | ||
</div> | ||
<div className="col-span-2 text-right"> | ||
<div className="flex items-center"> | ||
{!(collection.code === selectedCollection) && ( | ||
<button | ||
type="button" | ||
className="button secondary" | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
setSelectedCollection(collection.code); | ||
}} | ||
> | ||
Select | ||
</button> | ||
)} | ||
{collection.code === selectedCollection && ( | ||
<CheckIcon width={20} height={20} /> | ||
)} | ||
</div> | ||
</div> | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
</Card.Session> | ||
<Card.Session title="Number of products to display"> | ||
<div className="flex justify-between gap-8"> | ||
<Field | ||
type="text" | ||
name="settings[count]" | ||
value={count} | ||
validationRules={['notEmpty']} | ||
/> | ||
</div> | ||
</Card.Session> | ||
</div> | ||
<Card.Session> | ||
<div className="flex justify-between gap-8"> | ||
<SimplePageination | ||
total={data?.collections.total} | ||
count={data?.collections?.items?.length || 0} | ||
page={page} | ||
hasNext={limit * page < data?.collections.total} | ||
setPage={setPage} | ||
/> | ||
</div> | ||
</Card.Session> | ||
</div> | ||
); | ||
} | ||
|
||
CollectionProductsSetting.propTypes = { | ||
collectionProductsWidget: PropTypes.shape({ | ||
collection: PropTypes.string, | ||
count: PropTypes.number | ||
}) | ||
}; | ||
|
||
CollectionProductsSetting.defaultProps = { | ||
collectionProductsWidget: { | ||
collection: '', | ||
count: 5 | ||
} | ||
}; | ||
|
||
export default CollectionProductsSetting; | ||
|
||
export const query = ` | ||
query Query($collection: String, $count: Int) { | ||
collectionProductsWidget(collection: $collection, count: $count) { | ||
collection | ||
count | ||
} | ||
} | ||
`; | ||
|
||
export const variables = `{ | ||
collection: getWidgetSetting("collection"), | ||
count: getWidgetSetting("count") | ||
}`; |
Oops, something went wrong.