From 02578bda2a441d49f95f2cf57f33bc85560f8f7f Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Tue, 4 Feb 2020 16:56:34 -0800 Subject: [PATCH] Added association tracking --- bodyshop_translations.babel | 125 ++++++++++++++++++ .../profile-content.component.jsx | 3 +- .../profile-my/profile-my.component.jsx | 11 +- .../profile-shops/profile-shops.component.jsx | 52 ++++++++ .../profile-shops/profile-shops.container.jsx | 24 ++++ client/src/graphql/associations.queries.js | 27 ++++ client/src/pages/manage/manage.page.jsx | 2 +- client/src/redux/user/user.sagas.js | 3 - client/src/translations/en_us/common.json | 15 ++- client/src/translations/es/common.json | 15 ++- client/src/translations/fr/common.json | 15 ++- 11 files changed, 282 insertions(+), 10 deletions(-) create mode 100644 client/src/components/profile-shops/profile-shops.component.jsx create mode 100644 client/src/components/profile-shops/profile-shops.container.jsx create mode 100644 client/src/graphql/associations.queries.js diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 9e98b433c..a8d1c0021 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -18,6 +18,110 @@ translation + + associations + + + actions + + + activate + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + + + fields + + + active + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + shopname + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + + + labels + + + actions + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + + + + + documents @@ -4436,6 +4540,27 @@ + + updateprofile + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + diff --git a/client/src/components/profile-content/profile-content.component.jsx b/client/src/components/profile-content/profile-content.component.jsx index cc627a3fa..6854d4146 100644 --- a/client/src/components/profile-content/profile-content.component.jsx +++ b/client/src/components/profile-content/profile-content.component.jsx @@ -2,6 +2,7 @@ import React from "react"; import { useTranslation } from "react-i18next"; import AlertComponent from "../alert/alert.component"; import ProfileMyComponent from "../profile-my/profile-my.component"; +import ProfileShopsContainer from "../profile-shops/profile-shops.container"; export default function ProfileContent({ sidebarSelection }) { const { t } = useTranslation(); @@ -10,7 +11,7 @@ export default function ProfileContent({ sidebarSelection }) { case "profile": return ; case "shops": - return
Shop stuff
; + return ; default: return ( diff --git a/client/src/components/profile-my/profile-my.component.jsx b/client/src/components/profile-my/profile-my.component.jsx index a924f6666..6eb734b4c 100644 --- a/client/src/components/profile-my/profile-my.component.jsx +++ b/client/src/components/profile-my/profile-my.component.jsx @@ -44,7 +44,14 @@ export default connect( return (
- + {isFieldsTouched() ? ( + //TODO: Appropriate Error + resetFields()} + /> + ) : null} +
{getFieldDecorator("displayname", { @@ -58,7 +65,7 @@ export default connect( htmlType="submit" onClick={handleSubmit} > - Save + {t("user.actions.updateprofile")}
diff --git a/client/src/components/profile-shops/profile-shops.component.jsx b/client/src/components/profile-shops/profile-shops.component.jsx new file mode 100644 index 000000000..610aa25ee --- /dev/null +++ b/client/src/components/profile-shops/profile-shops.component.jsx @@ -0,0 +1,52 @@ +import React from "react"; +import { useTranslation } from "react-i18next"; +import { Table, Button } from "antd"; +export default function ProfileShopsComponent({ + loading, + data, + updateActiveShop +}) { + const { t } = useTranslation(); + + const columns = [ + { + title: t("associations.fields.shopname"), + dataIndex: "shopname", + key: "shopname", + width: "25%", + render: (text, record) => {record.bodyshop.shopname} + }, + { + title: t("associations.fields.active"), + dataIndex: "active", + key: "active", + width: "25%", + render: (text, record) => {record.active ? "Yes" : "No"} + }, + { + title: t("associations.labels.actions"), + dataIndex: "actions", + key: "actions", + width: "25%", + render: (text, record) => ( + + {record.active ? null : ( + + )} + + ) + } + ]; + + return ( + ({ ...item }))} + rowKey="id" + dataSource={data} + /> + ); +} diff --git a/client/src/components/profile-shops/profile-shops.container.jsx b/client/src/components/profile-shops/profile-shops.container.jsx new file mode 100644 index 000000000..bc85033d6 --- /dev/null +++ b/client/src/components/profile-shops/profile-shops.container.jsx @@ -0,0 +1,24 @@ +import React from "react"; +import { useQuery } from "react-apollo"; +import { QUERY_ALL_ASSOCIATIONS } from "../../graphql/associations.queries"; +import AlertComponent from "../alert/alert.component"; +import ProfileShopsComponent from "./profile-shops.component"; + +export default function ProfileShopsContainer() { + + const { loading, error, data, refetch } = useQuery(QUERY_ALL_ASSOCIATIONS); + + const updateActiveShop = activeShopId => { + console.log("activeShopId", activeShopId); + refetch(); + }; + + if (error) return ; + return ( + + ); +} diff --git a/client/src/graphql/associations.queries.js b/client/src/graphql/associations.queries.js new file mode 100644 index 000000000..b043e3c8a --- /dev/null +++ b/client/src/graphql/associations.queries.js @@ -0,0 +1,27 @@ +import { gql } from "apollo-boost"; + +export const QUERY_ALL_ASSOCIATIONS = gql` + query QUERY_ALL_ASSOCIATIONS { + associations { + id + active + bodyshop { + shopname + } + } + } +`; + +export const UPDATE_ASSOCIATION = gql` + mutation UPDATE_ASSOCIATION($assocId: uuid, $assocActive: Boolean) { + update_associations( + where: { id: { _eq: $assocId } } + _set: { active: $assocActive } + ) { + returning { + id + active + } + } + } +`; diff --git a/client/src/pages/manage/manage.page.jsx b/client/src/pages/manage/manage.page.jsx index 300815d4d..0ce1ce70a 100644 --- a/client/src/pages/manage/manage.page.jsx +++ b/client/src/pages/manage/manage.page.jsx @@ -28,7 +28,7 @@ const ChatWindowContainer = lazy(() => import("../../components/chat-window/chat-window.container") ); -const { Header, Content, Footer, Sider } = Layout; +const { Header, Content, Footer } = Layout; //This page will handle all routing for the entire application. export default function Manage({ match }) { const { t } = useTranslation(); diff --git a/client/src/redux/user/user.sagas.js b/client/src/redux/user/user.sagas.js index 1756cfe71..358105534 100644 --- a/client/src/redux/user/user.sagas.js +++ b/client/src/redux/user/user.sagas.js @@ -100,12 +100,9 @@ export function* updateUserDetails(userDetails) { export function* userSagas() { yield all([ - // call(onGoogleSignInStart), call(onEmailSignInStart), call(onCheckUserSession), call(onSignOutStart), call(onUpdateUserDetails) - // call(onEmailSignUpStart), - // call(onEmailSignUpSuccess) ]); } diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index fbe47e21d..a6b07413f 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -1,5 +1,17 @@ { "translation": { + "associations": { + "actions": { + "activate": "Activate" + }, + "fields": { + "active": "Active?", + "shopname": "Shop Name" + }, + "labels": { + "actions": "Actions" + } + }, "documents": { "errors": { "deletes3": "Error deleting document from storage. ", @@ -271,7 +283,8 @@ }, "user": { "actions": { - "signout": "Sign Out" + "signout": "Sign Out", + "updateprofile": "Update Profile" }, "fields": { "displayname": "Display Name" diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 7b8b37721..cd7e5e987 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -1,5 +1,17 @@ { "translation": { + "associations": { + "actions": { + "activate": "Activar" + }, + "fields": { + "active": "¿Activo?", + "shopname": "Nombre de tienda" + }, + "labels": { + "actions": "Comportamiento" + } + }, "documents": { "errors": { "deletes3": "Error al eliminar el documento del almacenamiento.", @@ -271,7 +283,8 @@ }, "user": { "actions": { - "signout": "desconectar" + "signout": "desconectar", + "updateprofile": "Actualización del perfil" }, "fields": { "displayname": "Nombre para mostrar" diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 5a5903129..2682efddb 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -1,5 +1,17 @@ { "translation": { + "associations": { + "actions": { + "activate": "Activer" + }, + "fields": { + "active": "Actif?", + "shopname": "nom de la boutique" + }, + "labels": { + "actions": "actes" + } + }, "documents": { "errors": { "deletes3": "Erreur lors de la suppression du document du stockage.", @@ -271,7 +283,8 @@ }, "user": { "actions": { - "signout": "Déconnexion" + "signout": "Déconnexion", + "updateprofile": "Mettre à jour le profil" }, "fields": { "displayname": "Afficher un nom"