From d1323bed7f3dcb29bc431522b0b4cc7936c7af5f Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Thu, 23 Jan 2020 12:12:04 -0800 Subject: [PATCH] Added job card functionality + new fields. --- bodyshop_translations.babel | 84 ++++++++++++++----- .../job-detail-cards.customer.component.jsx | 23 +++-- .../job-detail-cards.documents.component.jsx | 26 ++++-- .../job-detail-cards.documents.styles.scss | 11 +++ .../job-tombstone/job-tombstone.component.jsx | 2 +- ....page.jsx => jobs-documents.component.jsx} | 8 -- .../jobs-documents.container.jsx | 2 +- client/src/graphql/apollo-error-handling.js | 77 +++++++++-------- client/src/graphql/jobs.queries.js | 4 + client/src/translations/en_us/common.json | 6 +- client/src/translations/es/common.json | 6 +- client/src/translations/fr/common.json | 6 +- .../down.yaml | 3 + .../up.yaml | 3 + .../down.yaml | 36 ++++++++ .../up.yaml | 37 ++++++++ .../down.yaml | 34 ++++++++ .../up.yaml | 35 ++++++++ .../down.yaml | 36 ++++++++ .../up.yaml | 37 ++++++++ 20 files changed, 390 insertions(+), 86 deletions(-) create mode 100644 client/src/components/job-detail-cards/job-detail-cards.documents.styles.scss rename client/src/components/jobs-documents/{jobs-documents.page.jsx => jobs-documents.component.jsx} (96%) create mode 100644 hasura/migrations/1579808199913_alter_table_public_documents_add_column_key/down.yaml create mode 100644 hasura/migrations/1579808199913_alter_table_public_documents_add_column_key/up.yaml create mode 100644 hasura/migrations/1579808226020_update_permission_user_public_table_documents/down.yaml create mode 100644 hasura/migrations/1579808226020_update_permission_user_public_table_documents/up.yaml create mode 100644 hasura/migrations/1579808232227_update_permission_user_public_table_documents/down.yaml create mode 100644 hasura/migrations/1579808232227_update_permission_user_public_table_documents/up.yaml create mode 100644 hasura/migrations/1579808237403_update_permission_user_public_table_documents/down.yaml create mode 100644 hasura/migrations/1579808237403_update_permission_user_public_table_documents/up.yaml diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 5e4230e5f..ab02b5e27 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -374,6 +374,27 @@ + + convert + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + postInvoices false @@ -720,6 +741,27 @@ + + ownr_ea + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + phone1 false @@ -741,6 +783,27 @@ + + phoneshort + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + ro_number false @@ -1066,27 +1129,6 @@ - - convert - false - - - - - - en-US - false - - - es-MX - false - - - fr-CA - false - - - documents false diff --git a/client/src/components/job-detail-cards/job-detail-cards.customer.component.jsx b/client/src/components/job-detail-cards/job-detail-cards.customer.component.jsx index ffb3fc607..4c46fd8fb 100644 --- a/client/src/components/job-detail-cards/job-detail-cards.customer.component.jsx +++ b/client/src/components/job-detail-cards/job-detail-cards.customer.component.jsx @@ -13,16 +13,23 @@ export default function JobDetailCardsCustomerComponent({ loading, data }) { extraLink={data?.owner ? `/manage/owners/${data?.owner?.id}` : null}> {data ? ( -
{`${data?.ownr_fn ?? - ""} ${data.ownr_ln ?? ""}`}
+
{`${data?.ownr_fn ?? ""} ${data.ownr_ln ?? ""}`}
- {`${data?.ownr_ph1 ?? ""}`} + {t("jobs.fields.phoneshort")}: + {`${data?.ownr_ph1 ?? + t("general.labels.na")}`} +
+ +
+ {t("jobs.fields.ownr_ea")}: + {data?.ownr_ea ? ( + + {`${data?.ownr_ea ?? ""}`} + + ) : ( + t("general.labels.na") + )}
- {data?.ownr_ea ? ( - -
{`${data?.ownr_ea ?? ""}`}
-
- ) : null}
{`${data?.owner?.preferred_contact ?? ""}`}
diff --git a/client/src/components/job-detail-cards/job-detail-cards.documents.component.jsx b/client/src/components/job-detail-cards/job-detail-cards.documents.component.jsx index d09d4f241..bb726091b 100644 --- a/client/src/components/job-detail-cards/job-detail-cards.documents.component.jsx +++ b/client/src/components/job-detail-cards/job-detail-cards.documents.component.jsx @@ -1,16 +1,32 @@ import React from "react"; import { useTranslation } from "react-i18next"; import CardTemplate from "./job-detail-cards.template.component"; +import { Carousel } from "antd"; +import "./job-detail-cards.styles.scss"; export default function JobDetailCardsDocumentsComponent({ loading, data }) { const { t } = useTranslation(); + if (!data) + return ( + + null + + ); + return ( - - {data ? ( - - Documents stuff here. - + + {data.documents ? ( + + {data.documents.map(item => ( +
+ +
+ ))} +
) : null}
); diff --git a/client/src/components/job-detail-cards/job-detail-cards.documents.styles.scss b/client/src/components/job-detail-cards/job-detail-cards.documents.styles.scss new file mode 100644 index 000000000..d6df79a10 --- /dev/null +++ b/client/src/components/job-detail-cards/job-detail-cards.documents.styles.scss @@ -0,0 +1,11 @@ +.ant-carousel .slick-slide { + text-align: center; + height: 160px; + line-height: 160px; + background: #364d79; + overflow: hidden; + } + + .ant-carousel .slick-slide h3 { + color: #fff; + } \ No newline at end of file diff --git a/client/src/components/job-tombstone/job-tombstone.component.jsx b/client/src/components/job-tombstone/job-tombstone.component.jsx index 2f8b4b69d..3d6d2ba75 100644 --- a/client/src/components/job-tombstone/job-tombstone.component.jsx +++ b/client/src/components/job-tombstone/job-tombstone.component.jsx @@ -124,7 +124,7 @@ function JobTombstone({ job, ...otherProps }) { }); }); }}> - {t("jobs.labels.convert")} + {t("jobs.actions.convert")} , - test { let access_token = window.localStorage.getItem("token"); - console.log("graphQLErrors", graphQLErrors); - console.log("networkError", networkError); - console.log("operation", operation); - console.log("forward", forward); + // console.log("graphQLErrors", graphQLErrors); + // console.log("networkError", networkError); + // console.log("operation", operation); + // console.log("forward", forward); let expired = false; @@ -29,40 +29,45 @@ const errorLink = onError( if (access_token && access_token !== "undefined") { // Let's refresh token through async request return new Observable(observer => { - auth.currentUser - .getIdToken(true) - .then(function(idToken) { - if (!idToken) { - window.localStorage.removeItem("token"); - return console.log("Refresh token has expired"); - } - console.log("Got a new token", idToken); - window.localStorage.setItem("token", idToken); + const unsubscribeFromAuth = auth.onAuthStateChanged(async user => { + console.log("Auth change in error handling."); + if (user) { + user + .getIdToken(true) + .then(function(idToken) { + if (!idToken) { + window.localStorage.removeItem("token"); + return console.log("Refresh token has expired"); + } + console.log("Got a new token", idToken); + window.localStorage.setItem("token", idToken); - // reset the headers - operation.setContext(({ headers = {} }) => ({ - headers: { - // Re-add old headers - ...headers, - // Switch out old access token for new one - authorization: idToken ? `Bearer ${idToken}` : "" - } - })); + // reset the headers + operation.setContext(({ headers = {} }) => ({ + headers: { + // Re-add old headers + ...headers, + // Switch out old access token for new one + authorization: idToken ? `Bearer ${idToken}` : "" + } + })); - const subscriber = { - next: observer.next.bind(observer), - error: observer.error.bind(observer), - complete: observer.complete.bind(observer) - }; - console.log("About to resend the request."); - // Retry last failed request - forward(operation).subscribe(subscriber); - }) - .catch(error => { - // No refresh or client token available, we force user to login - console.log("Hit an error."); - observer.error(error); - }); + const subscriber = { + next: observer.next.bind(observer), + error: observer.error.bind(observer), + complete: observer.complete.bind(observer) + }; + console.log("About to resend the request."); + // Retry last failed request + forward(operation).subscribe(subscriber); + }) + .catch(error => { + // No refresh or client token available, we force user to login + console.log("Hit an error."); + observer.error(error); + }); + } + }); }); } } diff --git a/client/src/graphql/jobs.queries.js b/client/src/graphql/jobs.queries.js index 9441ff3ee..c74240b52 100644 --- a/client/src/graphql/jobs.queries.js +++ b/client/src/graphql/jobs.queries.js @@ -246,6 +246,10 @@ export const QUERY_JOB_CARD_DETAILS = gql` updated_at claim_total ded_amt + documents(limit: 3, order_by: { created_at: desc }) { + id + thumb_url + } vehicle { id plate_no diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 1fe0badc2..1f05f4fca 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -31,6 +31,7 @@ "actions": { "addDocuments": "Add Job Documents", "addNote": "Add Note", + "convert": "Convert", "postInvoices": "Post Invoices", "printCenter": "Print Center" }, @@ -51,7 +52,9 @@ "est_number": "Estimate Number", "owner": "Owner", "owner_owing": "Cust. Owes", + "ownr_ea": "Email", "phone1": "Phone 1", + "phoneshort": "PH", "ro_number": "RO #", "status": "Job Status", "vehicle": "Vehicle" @@ -62,7 +65,7 @@ "customer": "Customer Information", "damage": "Area of Damage", "dates": "Dates", - "documents": "Documents", + "documents": "Recent Documents", "estimator": "Estimator", "filehandler": "File Handler", "insurance": "Insurance Details", @@ -71,7 +74,6 @@ "totals": "Totals", "vehicle": "Vehicle" }, - "convert": "Convert", "documents": "Documents", "lines": "Estimate Lines", "notes": "Notes", diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index 217435473..69a689ff9 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -31,6 +31,7 @@ "actions": { "addDocuments": "Agregar documentos de trabajo", "addNote": "Añadir la nota", + "convert": "Convertir", "postInvoices": "Contabilizar facturas", "printCenter": "Centro de impresión" }, @@ -51,7 +52,9 @@ "est_number": "Numero Estimado", "owner": "Propietario", "owner_owing": "Cust. Debe", + "ownr_ea": "Email", "phone1": "Teléfono 1", + "phoneshort": "PH", "ro_number": "RO #", "status": "Estado del trabajo", "vehicle": "Vehículo" @@ -62,7 +65,7 @@ "customer": "Información al cliente", "damage": "Área de Daño", "dates": "fechas", - "documents": "documentos", + "documents": "Documentos recientes", "estimator": "Estimador", "filehandler": "File Handler", "insurance": "detalles del seguro", @@ -71,7 +74,6 @@ "totals": "Totales", "vehicle": "Vehículo" }, - "convert": "Convertir", "documents": "documentos", "lines": "Líneas estimadas", "notes": "Notas", diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index a3bdce8aa..01c49457b 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -31,6 +31,7 @@ "actions": { "addDocuments": "Ajouter des documents de travail", "addNote": "Ajouter une note", + "convert": "Convertir", "postInvoices": "Poster des factures", "printCenter": "Centre d'impression" }, @@ -51,7 +52,9 @@ "est_number": "Numéro d'estimation", "owner": "Propriétaire", "owner_owing": "Cust. Owes", + "ownr_ea": "Email", "phone1": "Téléphone 1", + "phoneshort": "PH", "ro_number": "RO #", "status": "Statut de l'emploi", "vehicle": "Véhicule" @@ -62,7 +65,7 @@ "customer": "Informations client", "damage": "Zone de dommages", "dates": "Rendez-vous", - "documents": "Les documents", + "documents": "Documents récents", "estimator": "Estimateur", "filehandler": "Gestionnaire de fichiers", "insurance": "Détails de l'assurance", @@ -71,7 +74,6 @@ "totals": "Totaux", "vehicle": "Véhicule" }, - "convert": "Convertir", "documents": "Les documents", "lines": "Estimer les lignes", "notes": "Remarques", diff --git a/hasura/migrations/1579808199913_alter_table_public_documents_add_column_key/down.yaml b/hasura/migrations/1579808199913_alter_table_public_documents_add_column_key/down.yaml new file mode 100644 index 000000000..796bf37da --- /dev/null +++ b/hasura/migrations/1579808199913_alter_table_public_documents_add_column_key/down.yaml @@ -0,0 +1,3 @@ +- args: + sql: ALTER TABLE "public"."documents" DROP COLUMN "key"; + type: run_sql diff --git a/hasura/migrations/1579808199913_alter_table_public_documents_add_column_key/up.yaml b/hasura/migrations/1579808199913_alter_table_public_documents_add_column_key/up.yaml new file mode 100644 index 000000000..7684d4abc --- /dev/null +++ b/hasura/migrations/1579808199913_alter_table_public_documents_add_column_key/up.yaml @@ -0,0 +1,3 @@ +- args: + sql: ALTER TABLE "public"."documents" ADD COLUMN "key" text NOT NULL DEFAULT '0'; + type: run_sql diff --git a/hasura/migrations/1579808226020_update_permission_user_public_table_documents/down.yaml b/hasura/migrations/1579808226020_update_permission_user_public_table_documents/down.yaml new file mode 100644 index 000000000..727382dec --- /dev/null +++ b/hasura/migrations/1579808226020_update_permission_user_public_table_documents/down.yaml @@ -0,0 +1,36 @@ +- args: + role: user + table: + name: documents + schema: public + type: drop_insert_permission +- args: + permission: + check: + job: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - name + - thumb_url + - uploaded_by + - url + - created_at + - updated_at + - id + - jobid + localPresets: + - key: "" + value: "" + set: {} + role: user + table: + name: documents + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1579808226020_update_permission_user_public_table_documents/up.yaml b/hasura/migrations/1579808226020_update_permission_user_public_table_documents/up.yaml new file mode 100644 index 000000000..2c0ca6648 --- /dev/null +++ b/hasura/migrations/1579808226020_update_permission_user_public_table_documents/up.yaml @@ -0,0 +1,37 @@ +- args: + role: user + table: + name: documents + schema: public + type: drop_insert_permission +- args: + permission: + check: + job: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - created_at + - id + - jobid + - key + - name + - thumb_url + - updated_at + - uploaded_by + - url + localPresets: + - key: "" + value: "" + set: {} + role: user + table: + name: documents + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1579808232227_update_permission_user_public_table_documents/down.yaml b/hasura/migrations/1579808232227_update_permission_user_public_table_documents/down.yaml new file mode 100644 index 000000000..18e6b72a5 --- /dev/null +++ b/hasura/migrations/1579808232227_update_permission_user_public_table_documents/down.yaml @@ -0,0 +1,34 @@ +- args: + role: user + table: + name: documents + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - name + - thumb_url + - uploaded_by + - url + - created_at + - updated_at + - id + - jobid + computed_fields: [] + filter: + job: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: documents + schema: public + type: create_select_permission diff --git a/hasura/migrations/1579808232227_update_permission_user_public_table_documents/up.yaml b/hasura/migrations/1579808232227_update_permission_user_public_table_documents/up.yaml new file mode 100644 index 000000000..3d103eca5 --- /dev/null +++ b/hasura/migrations/1579808232227_update_permission_user_public_table_documents/up.yaml @@ -0,0 +1,35 @@ +- args: + role: user + table: + name: documents + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - created_at + - id + - jobid + - key + - name + - thumb_url + - updated_at + - uploaded_by + - url + computed_fields: [] + filter: + job: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: documents + schema: public + type: create_select_permission diff --git a/hasura/migrations/1579808237403_update_permission_user_public_table_documents/down.yaml b/hasura/migrations/1579808237403_update_permission_user_public_table_documents/down.yaml new file mode 100644 index 000000000..085d3dac8 --- /dev/null +++ b/hasura/migrations/1579808237403_update_permission_user_public_table_documents/down.yaml @@ -0,0 +1,36 @@ +- args: + role: user + table: + name: documents + schema: public + type: drop_update_permission +- args: + permission: + columns: + - name + - thumb_url + - uploaded_by + - url + - created_at + - updated_at + - id + - jobid + filter: + job: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + localPresets: + - key: "" + value: "" + set: {} + role: user + table: + name: documents + schema: public + type: create_update_permission diff --git a/hasura/migrations/1579808237403_update_permission_user_public_table_documents/up.yaml b/hasura/migrations/1579808237403_update_permission_user_public_table_documents/up.yaml new file mode 100644 index 000000000..515730b23 --- /dev/null +++ b/hasura/migrations/1579808237403_update_permission_user_public_table_documents/up.yaml @@ -0,0 +1,37 @@ +- args: + role: user + table: + name: documents + schema: public + type: drop_update_permission +- args: + permission: + columns: + - created_at + - id + - jobid + - key + - name + - thumb_url + - updated_at + - uploaded_by + - url + filter: + job: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + localPresets: + - key: "" + value: "" + set: {} + role: user + table: + name: documents + schema: public + type: create_update_permission