From f4ec377da47e98972534aaab4b2e0f35074f6e4c Mon Sep 17 00:00:00 2001
From: Patrick Fic <>
Date: Wed, 28 Apr 2021 07:37:07 -0700
Subject: [PATCH] IO-948 Vendor add to phonebook
---
bodyshop_translations.babel | 136 ++++++++++++++++++
.../phonebook-form.container.jsx | 6 +-
.../vendors-form/vendors-form.component.jsx | 6 +
.../vendors-phonebook-add.component.jsx | 83 +++++++++++
client/src/translations/en_us/common.json | 12 +-
client/src/translations/es/common.json | 10 ++
client/src/translations/fr/common.json | 10 ++
.../down.yaml | 6 +
.../up.yaml | 17 +++
hasura/migrations/metadata.yaml | 12 ++
10 files changed, 295 insertions(+), 3 deletions(-)
create mode 100644 client/src/components/vendors-phonebook-add/vendors-phonebook-add.component.jsx
create mode 100644 hasura/migrations/1619620323182_update_permission_user_public_table_phonebook/down.yaml
create mode 100644 hasura/migrations/1619620323182_update_permission_user_public_table_phonebook/up.yaml
diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel
index 075b0ebd4..1a6bef6df 100644
--- a/bodyshop_translations.babel
+++ b/bodyshop_translations.babel
@@ -27022,6 +27022,53 @@
+
+ errors
+
+
+ adding
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
+
+ saving
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
+
+
fields
@@ -27300,9 +27347,77 @@
+
+ labels
+
+
+ vendorcategory
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
+
+
successes
+
+ added
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
+
+ deleted
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
saved
false
@@ -34534,6 +34649,27 @@
actions
+
+ addtophonebook
+ false
+
+
+
+
+
+ en-US
+ false
+
+
+ es-MX
+ false
+
+
+ fr-CA
+ false
+
+
+
new
false
diff --git a/client/src/components/phonebook-form/phonebook-form.container.jsx b/client/src/components/phonebook-form/phonebook-form.container.jsx
index 2b293f349..4a359f8f0 100644
--- a/client/src/components/phonebook-form/phonebook-form.container.jsx
+++ b/client/src/components/phonebook-form/phonebook-form.container.jsx
@@ -77,7 +77,7 @@ function PhonebookFormContainer({ refetch, bodyshop }) {
if (!result.errors) {
notification["success"]({
- message: t("Phonebook.successes.saved"),
+ message: t("phonebook.successes.saved"),
});
if (refetch) await refetch();
@@ -87,7 +87,9 @@ function PhonebookFormContainer({ refetch, bodyshop }) {
setFormLoading(false);
} else {
notification["error"]({
- message: t("Phonebook.errors.saving"),
+ message: t("phonebook.errors.saving", {
+ error: JSON.stringify(result.errors),
+ }),
});
setFormLoading(false);
diff --git a/client/src/components/vendors-form/vendors-form.component.jsx b/client/src/components/vendors-form/vendors-form.component.jsx
index e3eb1330c..f8005283d 100644
--- a/client/src/components/vendors-form/vendors-form.component.jsx
+++ b/client/src/components/vendors-form/vendors-form.component.jsx
@@ -20,6 +20,7 @@ import PhoneFormItem, {
PhoneItemFormatterValidation,
} from "../form-items-formatted/phone-form-item.component";
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
+import VendorsPhonebookAdd from "../vendors-phonebook-add/vendors-phonebook-add.component";
export default function VendorsFormComponent({
form,
formLoading,
@@ -53,6 +54,11 @@ export default function VendorsFormComponent({
+
+
}
/>
diff --git a/client/src/components/vendors-phonebook-add/vendors-phonebook-add.component.jsx b/client/src/components/vendors-phonebook-add/vendors-phonebook-add.component.jsx
new file mode 100644
index 000000000..f5dc41bfd
--- /dev/null
+++ b/client/src/components/vendors-phonebook-add/vendors-phonebook-add.component.jsx
@@ -0,0 +1,83 @@
+import { Button, notification } from "antd";
+import React, { useState } from "react";
+import { connect } from "react-redux";
+import { createStructuredSelector } from "reselect";
+import { selectBodyshop } from "../../redux/user/user.selectors";
+import { useTranslation } from "react-i18next";
+import { useMutation } from "@apollo/client";
+import { INSERT_NEW_PHONEBOOK } from "../../graphql/phonebook.queries";
+
+const mapStateToProps = createStructuredSelector({
+ bodyshop: selectBodyshop,
+});
+const mapDispatchToProps = (dispatch) => ({
+ //setUserLanguage: language => dispatch(setUserLanguage(language))
+});
+export default connect(
+ mapStateToProps,
+ mapDispatchToProps
+)(VendorsPhonebookAdd);
+
+export function VendorsPhonebookAdd({ form, bodyshop, disabled }) {
+ const [loading, setLoading] = useState(false);
+ const [insertPhonebook] = useMutation(INSERT_NEW_PHONEBOOK);
+ const { t } = useTranslation();
+
+ const handleAdd = async () => {
+ setLoading(true);
+
+ const VendorValues = form.getFieldsValue([
+ "name",
+ "email",
+ "phone",
+ "street1",
+ "street2",
+ "city",
+ "state",
+ "zip",
+ "country",
+ ]);
+ console.log(`VendorValues`, VendorValues);
+ const result = await insertPhonebook({
+ variables: {
+ phonebook_entry: [
+ {
+ //The phonebook obj,
+ bodyshopid: bodyshop.id,
+ company: VendorValues.name,
+ category: t("phonebook.labels.vendorcategory"),
+ address1: VendorValues.street1,
+ address2: VendorValues.street2,
+ city: VendorValues.city,
+ state: VendorValues.state,
+ zip: VendorValues.zip,
+ country: VendorValues.country,
+ phone1: VendorValues.phone,
+ email: VendorValues.email,
+ },
+ ],
+ },
+ });
+
+ if (result.errors) {
+ notification.open({
+ type: "error",
+ message: t("phonebook.errors.adding", {
+ error: JSON.stringify(result.errors),
+ }),
+ });
+ } else {
+ notification.open({
+ type: "success",
+ message: t("phonebook.successes.added"),
+ });
+ }
+ setLoading(false);
+ };
+
+ return (
+
+ );
+}
diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json
index fe3f687a4..29ea7f56b 100644
--- a/client/src/translations/en_us/common.json
+++ b/client/src/translations/en_us/common.json
@@ -1618,6 +1618,10 @@
"actions": {
"new": "New Phonebook Entry"
},
+ "errors": {
+ "adding": "Error adding phonebook entry. {{error}}",
+ "saving": "Error saving phonebook entry. {{error}}"
+ },
"fields": {
"category": "Category",
"city": "City",
@@ -1633,8 +1637,13 @@
"street1": "Street 1",
"street2": "Street 2"
},
+ "labels": {
+ "vendorcategory": "Vendor"
+ },
"successes": {
- "saved": ""
+ "added": "Phonebook entry added successfully. ",
+ "deleted": "Phonebook entry deleted successfully. ",
+ "saved": "Phonebook entry saved successfully. "
}
},
"printcenter": {
@@ -2077,6 +2086,7 @@
},
"vendors": {
"actions": {
+ "addtophonebook": "Add to Phonebook",
"new": "New Vendor",
"newpreferredmake": "New Preferred Make"
},
diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json
index ad781f52e..7aef1dede 100644
--- a/client/src/translations/es/common.json
+++ b/client/src/translations/es/common.json
@@ -1618,6 +1618,10 @@
"actions": {
"new": ""
},
+ "errors": {
+ "adding": "",
+ "saving": ""
+ },
"fields": {
"category": "",
"city": "",
@@ -1633,7 +1637,12 @@
"street1": "",
"street2": ""
},
+ "labels": {
+ "vendorcategory": ""
+ },
"successes": {
+ "added": "",
+ "deleted": "",
"saved": ""
}
},
@@ -2077,6 +2086,7 @@
},
"vendors": {
"actions": {
+ "addtophonebook": "",
"new": "Nuevo vendedor",
"newpreferredmake": ""
},
diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json
index 848ac9966..cef0a4e98 100644
--- a/client/src/translations/fr/common.json
+++ b/client/src/translations/fr/common.json
@@ -1618,6 +1618,10 @@
"actions": {
"new": ""
},
+ "errors": {
+ "adding": "",
+ "saving": ""
+ },
"fields": {
"category": "",
"city": "",
@@ -1633,7 +1637,12 @@
"street1": "",
"street2": ""
},
+ "labels": {
+ "vendorcategory": ""
+ },
"successes": {
+ "added": "",
+ "deleted": "",
"saved": ""
}
},
@@ -2077,6 +2086,7 @@
},
"vendors": {
"actions": {
+ "addtophonebook": "",
"new": "Nouveau vendeur",
"newpreferredmake": ""
},
diff --git a/hasura/migrations/1619620323182_update_permission_user_public_table_phonebook/down.yaml b/hasura/migrations/1619620323182_update_permission_user_public_table_phonebook/down.yaml
new file mode 100644
index 000000000..5354aae8c
--- /dev/null
+++ b/hasura/migrations/1619620323182_update_permission_user_public_table_phonebook/down.yaml
@@ -0,0 +1,6 @@
+- args:
+ role: user
+ table:
+ name: phonebook
+ schema: public
+ type: drop_delete_permission
diff --git a/hasura/migrations/1619620323182_update_permission_user_public_table_phonebook/up.yaml b/hasura/migrations/1619620323182_update_permission_user_public_table_phonebook/up.yaml
new file mode 100644
index 000000000..c6766a31b
--- /dev/null
+++ b/hasura/migrations/1619620323182_update_permission_user_public_table_phonebook/up.yaml
@@ -0,0 +1,17 @@
+- args:
+ permission:
+ backend_only: false
+ filter:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
+ role: user
+ table:
+ name: phonebook
+ schema: public
+ type: create_delete_permission
diff --git a/hasura/migrations/metadata.yaml b/hasura/migrations/metadata.yaml
index 91057abc5..b2e186913 100644
--- a/hasura/migrations/metadata.yaml
+++ b/hasura/migrations/metadata.yaml
@@ -3886,6 +3886,18 @@ tables:
- active:
_eq: true
check: null
+ delete_permissions:
+ - role: user
+ permission:
+ filter:
+ bodyshop:
+ associations:
+ _and:
+ - user:
+ authid:
+ _eq: X-Hasura-User-Id
+ - active:
+ _eq: true
- table:
schema: public
name: scoreboard