Skip to content

Commit

Permalink
feat(frontend): update change on master (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel authored Nov 6, 2020
1 parent bc801ff commit 7d51127
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 2 deletions.
1 change: 1 addition & 0 deletions targets/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "frontend",
"version": "1.0.0",
"dependencies": {
"@elastic/elasticsearch": "^7.9.1",
"@hapi/boom": "^9.1.0",
"@hapi/joi": "^17.1.1",
"@hookform/error-message": "^0.0.4",
Expand Down
29 changes: 29 additions & 0 deletions targets/frontend/src/pages/api/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Client } from "@elastic/elasticsearch";

export default async function (req, res) {
if (!process.env.ELASTICSEARCH_API_KEY || !process.env.ELASTICSEARCH_URL) {
res.status(304).json({ message: "not modified" });
}

const client = new Client({
auth: {
apiKey: process.env.ELASTICSEARCH_API_KEY,
},
node: `${process.env.ELASTICSEARCH_URL}`,
});

const { cdtnId, document } = req.body;
try {
await client.update({
body: {
doc: document,
},
id: cdtnId,
index: `cdtn_master_documents`,
});
res.json({ message: "doc updated!" });
} catch (response) {
console.error(response.body.error);
res.status(response.statusCode).json({ message: response.body.error });
}
}
9 changes: 7 additions & 2 deletions targets/frontend/src/pages/contenus/[id].js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Inline } from "src/components/layout/Inline";
import { Stack } from "src/components/layout/Stack";
import { withCustomUrqlClient } from "src/hoc/CustomUrqlClient";
import { withUserProvider } from "src/hoc/UserProvider";
import { request } from "src/lib/request";
import { Card, jsx, Message, NavLink } from "theme-ui";
import { useMutation, useQuery } from "urql";

Expand Down Expand Up @@ -46,7 +47,7 @@ mutation updateDocument($cdtnId: String!, $metaDescription: String!, $title: Str
cdtn_id: $cdtnId
}
){
cdtn_id
cdtnId:cdtn_id, title, metaDescription: meta_description, document
}
}`;

Expand Down Expand Up @@ -78,7 +79,11 @@ export function DocumentsPage() {
document: jsonDoc.current.document,
metaDescription: jsonDoc.current.meta_description,
title: jsonDoc.current.title,
}).then((result) => {
}).then(({ data }) => {
const { cdtnId, title, metaDescription, document } = data.document;
request("/api/preview", {
body: { cdtnId, document: { ...document, metaDescription, title } },
});
if (result.error) {
console.error(result.error);
}
Expand Down
23 changes: 23 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,17 @@
enabled "2.0.x"
kuler "^2.0.0"

"@elastic/elasticsearch@^7.9.1":
version "7.9.1"
resolved "https://registry.yarnpkg.com/@elastic/elasticsearch/-/elasticsearch-7.9.1.tgz#40f1c38e8f70d783851c13be78a7cb346891c15e"
integrity sha512-NfPADbm9tRK/4ohpm9+aBtJ8WPKQqQaReyBKT225pi2oKQO1IzRlfM+OPplAvbhoH1efrSj1NKk27L+4BCrzXQ==
dependencies:
debug "^4.1.1"
decompress-response "^4.2.0"
ms "^2.1.1"
pump "^3.0.0"
secure-json-parse "^2.1.0"

"@emotion/cache@^10.0.27":
version "10.0.29"
resolved "https://registry.yarnpkg.com/@emotion/cache/-/cache-10.0.29.tgz#87e7e64f412c060102d589fe7c6dc042e6f9d1e0"
Expand Down Expand Up @@ -6063,6 +6074,13 @@ decode-uri-component@^0.2.0:
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=

decompress-response@^4.2.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-4.2.1.tgz#414023cc7a302da25ce2ec82d0d5238ccafd8986"
integrity sha512-jOSne2qbyE+/r8G1VU+G/82LBs2Fs4LAsTiLSHOCOMZQl2OKZ6i8i4IyHemTe+/yIXOtTcRQMzPcgyhoFlqPkw==
dependencies:
mimic-response "^2.0.0"

decompress-response@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-5.0.0.tgz#7849396e80e3d1eba8cb2f75ef4930f76461cb0f"
Expand Down Expand Up @@ -12881,6 +12899,11 @@ section-iterator@^2.0.0:
resolved "https://registry.yarnpkg.com/section-iterator/-/section-iterator-2.0.0.tgz#bf444d7afeeb94ad43c39ad2fb26151627ccba2a"
integrity sha1-v0RNev7rlK1Dw5rS+yYVFifMuio=

secure-json-parse@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/secure-json-parse/-/secure-json-parse-2.1.0.tgz#ae76f5624256b5c497af887090a5d9e156c9fb20"
integrity sha512-GckO+MS/wT4UogDyoI/H/S1L0MCcKS1XX/vp48wfmU7Nw4woBmb8mIpu4zPBQjKlRT88/bt9xdoV4111jPpNJA==

semver-compare@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"
Expand Down

0 comments on commit 7d51127

Please sign in to comment.