From 7577a15d92c0edae251ad16f17fb4235b270213f Mon Sep 17 00:00:00 2001 From: Andrey Dolgolev Date: Tue, 27 Jul 2021 18:15:03 +0300 Subject: [PATCH 1/4] temp state of subscription. --- frontend/pages/subscriptions.js | 2 +- frontend/sample.env | 7 ----- frontend/src/components/NewSubscription.js | 12 ++++---- frontend/src/components/SubscriptionsList.js | 9 +++--- frontend/src/core/hooks/useSubscriptions.js | 29 +++++++++++++------ .../core/services/subscriptions.service.js | 28 +++++++++++++----- frontend/src/core/utils/mockupRequests.js | 12 ++++---- 7 files changed, 60 insertions(+), 39 deletions(-) delete mode 100644 frontend/sample.env diff --git a/frontend/pages/subscriptions.js b/frontend/pages/subscriptions.js index 54450d7d..a2afea4f 100644 --- a/frontend/pages/subscriptions.js +++ b/frontend/pages/subscriptions.js @@ -100,7 +100,7 @@ const Subscriptions = () => { Add new - + )} diff --git a/frontend/sample.env b/frontend/sample.env deleted file mode 100644 index 93aff9b8..00000000 --- a/frontend/sample.env +++ /dev/null @@ -1,7 +0,0 @@ -export REACT_APP_SIMIOTICS_SEARCH_URL=http://localhost:5000 -export REACT_APP_MIXPANEL_TOKEN="" -export REACT_APP_SIMIOTICS_AUTH_URL=http://localhost:7474 -export REACT_APP_SIMIOTICS_JOURNALS_URL=http://localhost:7475 -export REACT_APP_BUGOUT_CONTACTUS_TOKEN="" -export REACT_APP_BUGOUT_CONTACTUS_JOURNAL_ID="" -export REACT_APP_STRIPE_PUBLISHABLE_KEY="" diff --git a/frontend/src/components/NewSubscription.js b/frontend/src/components/NewSubscription.js index beb4ff8f..aa31450c 100644 --- a/frontend/src/components/NewSubscription.js +++ b/frontend/src/components/NewSubscription.js @@ -44,6 +44,7 @@ const NewSubscription = ({ isFreeOption, onClose }) => { type: isFreeOption ? "free" : radioState, }); }; + console.log(typesCache.data); return (
Subscribe to a new address @@ -68,9 +69,9 @@ const NewSubscription = ({ isFreeOption, onClose }) => { - {typesCache.data.map((type) => { + {typesCache.data.subscriptions.map((type) => { const radio = getRadioProps({ - value: type.subscription_type, + value: type.id, isDisabled: !type.active || (isFreeOption && @@ -79,8 +80,8 @@ const NewSubscription = ({ isFreeOption, onClose }) => { if (!type.subscription_plan_id) return ""; return ( console.log("hello")} - key={`subscription-type-${type.id}`} + onClick={() => setRadioState(type.id)} + key={`subscription_type_${type.id}`} {...radio} > {type.name} @@ -90,9 +91,10 @@ const NewSubscription = ({ isFreeOption, onClose }) => { + diff --git a/frontend/src/components/SubscriptionsList.js b/frontend/src/components/SubscriptionsList.js index 49fc4487..3293724e 100644 --- a/frontend/src/components/SubscriptionsList.js +++ b/frontend/src/components/SubscriptionsList.js @@ -18,13 +18,14 @@ import CopyButton from "./CopyButton"; import { useSubscriptions } from "../core/hooks"; import ConfirmationRequest from "./ConfirmationRequest"; -const List = () => { +const List = (data) => { const { subscriptionsCache, changeNote, deleteSubscription } = useSubscriptions(); const updateCallback = ({ id, note }) => { changeNote.mutate({ id, note }); }; + console.log(data); if (subscriptionsCache.data) { return ( @@ -45,7 +46,7 @@ const List = () => { Token Address Date Created - Note + label Actions @@ -85,11 +86,11 @@ const List = () => { updateCallback({ id: subscription.id, - note: nextValue, + label: nextValue, }) } > diff --git a/frontend/src/core/hooks/useSubscriptions.js b/frontend/src/core/hooks/useSubscriptions.js index 422ca0ec..64c798c9 100644 --- a/frontend/src/core/hooks/useSubscriptions.js +++ b/frontend/src/core/hooks/useSubscriptions.js @@ -27,7 +27,9 @@ const useSubscriptions = () => { const getSubscriptions = async () => { const response = await SubscriptionsService.getSubscriptions(); - return response.data.data; + console.log("getSubscriptions"); + console.log(response.data); + return response.data; }; const subscriptionsCache = useQuery(["subscriptions"], getSubscriptions, { @@ -39,7 +41,7 @@ const useSubscriptions = () => { const getSubscriptionTypes = async () => { const response = await SubscriptionsService.getTypes(); - return response.data.data; + return response.data; }; const typesCache = useQuery(["subscription_types"], getSubscriptionTypes, { @@ -73,14 +75,23 @@ const useSubscriptions = () => { }, }); - const deleteSubscription = useMutation(SubscriptionsService.deleteSubscription(), { - onError: (error) => toast(error, "error"), - onSuccess: (response) => { - subscriptionsCache.refetch(); - }, - }); + const deleteSubscription = useMutation( + SubscriptionsService.deleteSubscription(), + { + onError: (error) => toast(error, "error"), + onSuccess: (response) => { + subscriptionsCache.refetch(); + }, + } + ); - return { createSubscription, subscriptionsCache, typesCache, changeNote, deleteSubscription }; + return { + createSubscription, + subscriptionsCache, + typesCache, + changeNote, + deleteSubscription, + }; }; export default useSubscriptions; diff --git a/frontend/src/core/services/subscriptions.service.js b/frontend/src/core/services/subscriptions.service.js index b00a515e..6987167b 100644 --- a/frontend/src/core/services/subscriptions.service.js +++ b/frontend/src/core/services/subscriptions.service.js @@ -1,18 +1,31 @@ import { http } from "../utils"; // import axios from "axios"; -const API = process.env.NEXT_PUBLIC_SIMIOTICS_AUTH_URL; +const API = process.env.NEXT_PUBLIC_MOONSTREAM_API_URL; +console.log(API); + +// export const getTypes = () => +// http({ +// method: "GET", +// url: `${API}/subscription_types/`, +// }); + +// export const getSubscriptions = () => +// http({ +// method: "GET", +// url: `${API}/subscriptions/`, +// }); export const getTypes = () => http({ method: "GET", - url: `${API}/subscription_types/`, + url: `${API}/subscriptions/types`, }); export const getSubscriptions = () => http({ method: "GET", - url: `${API}/subscriptions/`, + url: `${API}/subscriptions`, }); export const create = ({ address, note, blockchain }) => { @@ -35,12 +48,13 @@ export const deleteJournal = (id) => () => export const createSubscription = () => - ({ address, type, note }) => { - console.log("createSubscription: ", address, type, note); + ({ address, type, label, color }) => { + console.log("createSubscription: ", address, type, label); const data = new FormData(); data.append("address", address); - data.append("subscription_type", type); - data.append("note", note); + data.append("subscription_type_id", type); + data.append("color", color); + data.append("label", label); return http({ method: "POST", url: `${API}/subscriptions/`, diff --git a/frontend/src/core/utils/mockupRequests.js b/frontend/src/core/utils/mockupRequests.js index b96c62c7..75cf33cb 100644 --- a/frontend/src/core/utils/mockupRequests.js +++ b/frontend/src/core/utils/mockupRequests.js @@ -90,12 +90,12 @@ const enableMockupRequests = (axiosInstance) => { ], }); - mock.onGet(`${MOCK_API}/subscriptions/`).reply(200, { - data: { - is_free_subscription_availible: true, - subscriptions: MockSubscriptions, - }, - }); + // mock.onGet(`${MOCK_API}/subscriptions/`).reply(200, { + // data: { + // is_free_subscription_availible: true, + // subscriptions: MockSubscriptions, + // }, + // }); mock.onPost(`${MOCK_API}/subscriptions/`).reply((config) => { const params = config.data; // FormData of {name: ..., file: ...} From a560cc82d724bd6f916bb822064b8e46c77d6079 Mon Sep 17 00:00:00 2001 From: Andrey Dolgolev Date: Tue, 27 Jul 2021 20:11:08 +0300 Subject: [PATCH 2/4] Fix env --- frontend/sample.env | 9 +++++++++ frontend/src/core/utils/mockupRequests.js | 23 ----------------------- 2 files changed, 9 insertions(+), 23 deletions(-) create mode 100644 frontend/sample.env diff --git a/frontend/sample.env b/frontend/sample.env new file mode 100644 index 00000000..11a611c8 --- /dev/null +++ b/frontend/sample.env @@ -0,0 +1,9 @@ +export REACT_APP_SIMIOTICS_SEARCH_URL=http://localhost:5000 +export REACT_APP_MIXPANEL_TOKEN="" +export REACT_APP_SIMIOTICS_AUTH_URL=http://localhost:7474 +export REACT_APP_SIMIOTICS_JOURNALS_URL=http://localhost:7475 +export REACT_APP_BUGOUT_CONTACTUS_TOKEN="" +export REACT_APP_BUGOUT_CONTACTUS_JOURNAL_ID="" +export REACT_APP_STRIPE_PUBLISHABLE_KEY="" +export NEXT_PUBLIC_MOONSTREAM_API_URL=http://localhost:7481 + diff --git a/frontend/src/core/utils/mockupRequests.js b/frontend/src/core/utils/mockupRequests.js index 1b8985a7..fcb6cd49 100644 --- a/frontend/src/core/utils/mockupRequests.js +++ b/frontend/src/core/utils/mockupRequests.js @@ -234,28 +234,5 @@ const enableMockupRequests = (axiosInstance) => { offset: 0, }, }); - - // mock.onGet(`${MOCK_API}/subscriptions/`).reply(200, { - // data: { - // is_free_subscription_availible: true, - // subscriptions: MockSubscriptions, - // }, - // }); - - // mock.onPost(`${MOCK_API}/subscriptions/`).reply((config) => { - // const params = config.data; // FormData of {name: ..., file: ...} - // const id = params.get("id"); - // const label = params.get("label"); - // const address = params.get("address"); - // const subscription_type = params.get("subscription_type"); - - // return new Promise(function (resolve) { - // setTimeout(function () { - // const data = { id, label, address, subscription_type }; - // MockSubscriptions.push({ ...data }); - // resolve([200, { message: "OK", result: true }]); - // }, 1000); - // }); - // }); }; export default enableMockupRequests; From 51801bd91a0a4ab980ecff7e671ea9954774d790 Mon Sep 17 00:00:00 2001 From: Andrey Dolgolev Date: Tue, 27 Jul 2021 20:12:51 +0300 Subject: [PATCH 3/4] Remove onclick --- frontend/src/components/NewSubscription.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/frontend/src/components/NewSubscription.js b/frontend/src/components/NewSubscription.js index 951f6b21..3994d8ff 100644 --- a/frontend/src/components/NewSubscription.js +++ b/frontend/src/components/NewSubscription.js @@ -95,11 +95,7 @@ const NewSubscription = ({ isFreeOption, onClose }) => { }); if (!type.subscription_plan_id) return ""; return ( - setRadioState(type.id)} - key={`subscription_type_${type.id}`} - {...radio} - > + {type.name} ); From 47bc31d9bedc5ab05a54ab5ee8453d62add11e1b Mon Sep 17 00:00:00 2001 From: Andrey Dolgolev Date: Tue, 27 Jul 2021 20:17:57 +0300 Subject: [PATCH 4/4] Add fixes. --- frontend/sample.env | 14 +++++++------- frontend/src/components/NewSubscription.js | 2 +- frontend/src/components/SubscriptionsList.js | 2 -- frontend/src/core/hooks/useSubscriptions.js | 2 -- .../src/core/services/subscriptions.service.js | 2 -- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/frontend/sample.env b/frontend/sample.env index 11a611c8..e295fc84 100644 --- a/frontend/sample.env +++ b/frontend/sample.env @@ -1,9 +1,9 @@ -export REACT_APP_SIMIOTICS_SEARCH_URL=http://localhost:5000 -export REACT_APP_MIXPANEL_TOKEN="" -export REACT_APP_SIMIOTICS_AUTH_URL=http://localhost:7474 -export REACT_APP_SIMIOTICS_JOURNALS_URL=http://localhost:7475 -export REACT_APP_BUGOUT_CONTACTUS_TOKEN="" -export REACT_APP_BUGOUT_CONTACTUS_JOURNAL_ID="" -export REACT_APP_STRIPE_PUBLISHABLE_KEY="" +export NEXT_PUBLIC_SIMIOTICS_SEARCH_URL=http://localhost:5000 +export NEXT_PUBLIC_MIXPANEL_TOKEN="" +export NEXT_PUBLIC_SIMIOTICS_AUTH_URL=http://localhost:7474 +export NEXT_PUBLIC_SIMIOTICS_JOURNALS_URL=http://localhost:7475 +export NEXT_PUBLIC_BUGOUT_CONTACTUS_TOKEN="" +export NEXT_PUBLIC_BUGOUT_CONTACTUS_JOURNAL_ID="" +export NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="" export NEXT_PUBLIC_MOONSTREAM_API_URL=http://localhost:7481 diff --git a/frontend/src/components/NewSubscription.js b/frontend/src/components/NewSubscription.js index 3994d8ff..2f068188 100644 --- a/frontend/src/components/NewSubscription.js +++ b/frontend/src/components/NewSubscription.js @@ -44,7 +44,7 @@ const NewSubscription = ({ isFreeOption, onClose }) => { type: isFreeOption ? "free" : radioState, }); }; - console.log(typesCache.data); + return ( Subscribe to a new address diff --git a/frontend/src/components/SubscriptionsList.js b/frontend/src/components/SubscriptionsList.js index dee053fe..f34a89e8 100644 --- a/frontend/src/components/SubscriptionsList.js +++ b/frontend/src/components/SubscriptionsList.js @@ -23,10 +23,8 @@ const List = (data) => { useSubscriptions(); const updateCallback = ({ id, note }) => { - console.log("updateCallback", id); changeNote.mutate({ id, note }); }; - console.log(data); if (subscriptionsCache.data) { return ( diff --git a/frontend/src/core/hooks/useSubscriptions.js b/frontend/src/core/hooks/useSubscriptions.js index 64c798c9..54903d31 100644 --- a/frontend/src/core/hooks/useSubscriptions.js +++ b/frontend/src/core/hooks/useSubscriptions.js @@ -27,8 +27,6 @@ const useSubscriptions = () => { const getSubscriptions = async () => { const response = await SubscriptionsService.getSubscriptions(); - console.log("getSubscriptions"); - console.log(response.data); return response.data; }; diff --git a/frontend/src/core/services/subscriptions.service.js b/frontend/src/core/services/subscriptions.service.js index 755db3d6..62950c63 100644 --- a/frontend/src/core/services/subscriptions.service.js +++ b/frontend/src/core/services/subscriptions.service.js @@ -2,7 +2,6 @@ import { http } from "../utils"; // import axios from "axios"; const API = process.env.NEXT_PUBLIC_MOONSTREAM_API_URL; -console.log(API); export const getStream = ({ searchTerm, limit, offset, isContent }) => http({ @@ -49,7 +48,6 @@ export const deleteJournal = (id) => () => export const createSubscription = () => ({ address, type, label, color }) => { - console.log("createSubscription: ", address, type, label); const data = new FormData(); data.append("address", address); data.append("subscription_type_id", type);