diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..9ad7769 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,82 @@ +# Changelog + +## key + +Changelog entries are classified using the following labels _(from [keep-a-changelog][]_): + +- `added`: for new features +- `changed`: for changes in existing functionality +- `deprecated`: for once-stable features removed in upcoming releases +- `removed`: for deprecated features removed in this release +- `fixed`: for any bug fixes + +## [0.1.4] - 2020-12-22 + +### Changed + +- Notifications settings to use `.toggle()`, see [strapi api](https://strapi.io/documentation/developer-docs/latest/plugin-development/frontend-development.html#api) for more information [[e066cac](https://github.com/danestves/strapi-plugin-preview-content/commit/e066cac)] + +## [0.1.3] - 2020-12-21 + +### Fixed + +- Function to creatr or update the settings [[be947f5](https://github.com/danestves/strapi-plugin-preview-content/commit/be947f5)] + +## [0.1.0] - 2020-12-21 + +### Fixed + +- Import lodash in service [[4bf38ef](https://github.com/danestves/strapi-plugin-preview-content/commit/4bf38ef)] + +## [0.0.8] - 2020-12-21 + +### Added + +- Get preview url from database [[9a2176f](https://github.com/danestves/strapi-plugin-preview-content/commit/9a2176f)] + +### Fixed + +- Missing translations `en` [[c2e25e2](https://github.com/danestves/strapi-plugin-preview-content/commit/c2e25e2)] + +## [0.0.6] - 2020-12-21 + +### Added + +- Support for models in `npm` [[0ddb702](https://github.com/danestves/strapi-plugin-preview-content/commit/0ddb702)] + +## [0.0.5] - 2020-12-21 + +### Removed + +- Deleting packages not needed [[1200b81](https://github.com/danestves/strapi-plugin-preview-content/commit/1200b81)] + +## [0.0.4] - 2020-12-21 + +### Added + +- Script to compile and ignore files in `.gitignore` [[aaa5bed](https://github.com/danestves/strapi-plugin-preview-content/commit/aaa5bed)] + +## [0.0.3] - 2020-12-21 + +### Added + +- Support for Strapi 3.4 files [[669f535](https://github.com/danestves/strapi-plugin-preview-content/commit/669f535)] + +## [0.0.2] - 2020-12-21 + +### Added + +- All routes with initial vanilla javascript [[8b099b4](https://github.com/danestves/strapi-plugin-preview-content/commit/8b099b4)] +- TypeScript support for all the plugin [[d51b9f0](https://github.com/danestves/strapi-plugin-preview-content/commit/d51b9f0)] + +## Fixed + +- Empty strapi package [[9ff05cf](https://github.com/danestves/strapi-plugin-preview-content/commit/9ff05cf)] + +## [0.0.1] - 2020-12-21 + +### Added + +- Init repository with basic funcionality [[9a1ce22](https://github.com/danestves/strapi-plugin-preview-content/commit/9a1ce22)] + +[keep-a-changelog]: https://github.com/olivierlacan/keep-a-changelog diff --git a/package.json b/package.json index bd16bbb..213a032 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "strapi-plugin-preview-content", - "version": "0.1.3", + "version": "0.2.2", "description": "Preview your content with custom URL.", "main": "admin/main/index.js", "strapi": { diff --git a/src/admin/main/preview-context/index.js b/src/admin/main/preview-context/index.js index 8a61163..c10f6bf 100644 --- a/src/admin/main/preview-context/index.js +++ b/src/admin/main/preview-context/index.js @@ -75,19 +75,18 @@ export const PreviewProvider = ({ params, } ); + if (data.url) { window.open(data.url, "_blank"); } else { - strapi.notification.config({ - type: "error", - message: getPreviewPluginTrad("error.previewUrl.notFound"), - }); + strapi.notification.error( + getPreviewPluginTrad("error.previewUrl.notFound") + ); } } catch (_e) { - strapi.notification.config({ - type: "error", - message: getPreviewPluginTrad("error.previewUrl.notFound"), - }); + strapi.notification.error( + getPreviewPluginTrad("error.previewUrl.notFound") + ); } }, type: "button", @@ -113,6 +112,7 @@ export const PreviewProvider = ({ paddingLeft: 15, paddingRight: 15, fontWeight: 600, + minWidth: 100, }, }); } else { @@ -128,6 +128,7 @@ export const PreviewProvider = ({ paddingLeft: 15, paddingRight: 15, fontWeight: 600, + minWidth: 75, }, }); } @@ -150,36 +151,25 @@ export const PreviewProvider = ({ try { // Show the loading state setButtonLoading(true); - const clonedPayload = await request(getRequestUrl(slug), { - method: "GET", - body: { - ...initialData, - cloneOf: initialData.id, - options: { - ...initialData.options, - previewable: true, - }, - }, - }); - strapi.notification.config({ - type: "success", - message: getPreviewPluginTrad("success.record.clone"), - }); + strapi.notification.success(getPreviewPluginTrad("success.record.clone")); - window.location.replace(getFrontendEntityUrl(slug, clonedPayload.id)); + window.location.replace(getFrontendEntityUrl(slug, initialData.id)); } catch (err) { + console.log(err); const errorMessage = get( err, "response.payload.message", formatMessage({ id: getPreviewPluginTrad("error.record.clone") }) ); + strapi.notification.error(errorMessage); } finally { setButtonLoading(false); toggleWarningClone(); } }; + const handleConfirmPreviewPublish = async () => { try { // Show the loading state @@ -201,10 +191,10 @@ export const PreviewProvider = ({ method: "DELETE", }); - strapi.notification.config({ - type: "success", - message: getPreviewPluginTrad("success.record.publish"), - }); + strapi.notification.success( + getPreviewPluginTrad("success.record.publish") + ); + window.location.replace(getFrontendEntityUrl(slug, targetId)); } catch (err) { const errorMessage = get( @@ -212,10 +202,8 @@ export const PreviewProvider = ({ "response.payload.message", formatMessage({ id: getPreviewPluginTrad("error.record.publish") }) ); - strapi.notification.config({ - type: "error", - message: errorMessage, - }); + + strapi.notification.error(errorMessage); } finally { setButtonLoading(false); toggleWarningPublish(); @@ -296,7 +284,7 @@ function prepareToPublish(payload) { } const getRequestUrl = (path) => - `/${CONTENT_MANAGER_PLUGIN_ID}/collection-types/${path}/${id}`; + `/${CONTENT_MANAGER_PLUGIN_ID}/explorer/${path}`; const getFrontendEntityUrl = (path, id) => `/admin/plugins/${CONTENT_MANAGER_PLUGIN_ID}/collectionType/${path}/create/clone/${id}`; diff --git a/src/services/preview.ts b/src/services/preview.ts index 1ba6ca5..5f6c433 100644 --- a/src/services/preview.ts +++ b/src/services/preview.ts @@ -125,11 +125,6 @@ module.exports = { const entity: any = _.first(results) || null; const previewUrl = entity.baseUrl || ""; - console.log({ entity }); - console.log({ previewUrl }); - console.log({ - url: this.replacePreviewParams(contentType, contentId, previewUrl), - }); return this.replacePreviewParams(contentType, contentId, previewUrl); },