diff --git a/bodyshop_translations.babel b/bodyshop_translations.babel index 162ad5ab9..861135c34 100644 --- a/bodyshop_translations.babel +++ b/bodyshop_translations.babel @@ -578,6 +578,27 @@ errors + + creating + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + deleted false @@ -2205,6 +2226,27 @@ labels + + available_new_jobs + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + cards @@ -2462,6 +2504,27 @@ + + creating_new_job + false + + + + + + en-US + false + + + es-MX + false + + + fr-CA + false + + + documents false diff --git a/client/src/components/jobs-available-new/jobs-available-new.component.jsx b/client/src/components/jobs-available-new/jobs-available-new.component.jsx index 3638188d4..b7dd1d880 100644 --- a/client/src/components/jobs-available-new/jobs-available-new.component.jsx +++ b/client/src/components/jobs-available-new/jobs-available-new.component.jsx @@ -10,23 +10,22 @@ export default function JobsAvailableComponent({ refetch, deleteJob, deleteAllNewJobs, - estDataLazyLoad, onModalOk, onModalCancel, modalVisible, setModalVisible, - selectedOwner, setSelectedOwner + selectedOwner, + setSelectedOwner, + loadEstData, + estData }) { const { t } = useTranslation(); - const [loadEstData, estData] = estDataLazyLoad; const [state, setState] = useState({ sortedInfo: {}, filteredInfo: { text: "" } }); - - const handleTableChange = (pagination, filters, sorter) => { setState({ ...state, filteredInfo: filters, sortedInfo: sorter }); }; diff --git a/client/src/components/jobs-available-new/jobs-available-new.container.jsx b/client/src/components/jobs-available-new/jobs-available-new.container.jsx index 93afc1f68..7c1932d9d 100644 --- a/client/src/components/jobs-available-new/jobs-available-new.container.jsx +++ b/client/src/components/jobs-available-new/jobs-available-new.container.jsx @@ -1,56 +1,125 @@ +import { notification } from "antd"; import React, { useState } from "react"; import { useMutation, useQuery } from "react-apollo"; -import { - DELETE_ALL_AVAILABLE_NEW_JOBS, - QUERY_AVAILABLE_NEW_JOBS -} from "../../graphql/available-jobs.queries"; +import { useTranslation } from "react-i18next"; +import { withRouter } from "react-router-dom"; +import { DELETE_ALL_AVAILABLE_NEW_JOBS, QUERY_AVAILABLE_NEW_JOBS } from "../../graphql/available-jobs.queries"; import { INSERT_NEW_JOB } from "../../graphql/jobs.queries"; import AlertComponent from "../alert/alert.component"; +import LoadingSpinner from "../loading-spinner/loading-spinner.component"; import JobsAvailableComponent from "./jobs-available-new.component"; -export default function JobsAvailableContainer({ deleteJob, estDataLazyLoad }) { +export default withRouter(function JobsAvailableContainer({ + deleteJob, + estDataLazyLoad, + history +}) { const { loading, error, data, refetch } = useQuery(QUERY_AVAILABLE_NEW_JOBS, { fetchPolicy: "network-only" }); + const { t } = useTranslation(); + const [modalVisible, setModalVisible] = useState(false); const [selectedOwner, setSelectedOwner] = useState(null); + const [insertLoading, setInsertLoading] = useState(false); const [deleteAllNewJobs] = useMutation(DELETE_ALL_AVAILABLE_NEW_JOBS); const [insertNewJob] = useMutation(INSERT_NEW_JOB); + const [loadEstData, estData] = estDataLazyLoad; const onModalOk = () => { setModalVisible(false); console.log("selectedOwner", selectedOwner); - // insertNewJob({ - // variables: { - // job: record.est_data - // } - // }).then(r => { - // notification["success"]({ - // message: t("jobs.successes.created") - // }); - // refetch(); - // }); + setInsertLoading(true); + console.log( + "logitest", + estData.data && + estData.data.available_jobs_by_pk && + estData.data.available_jobs_by_pk.est_data + ); + + if ( + !( + estData.data && + estData.data.available_jobs_by_pk && + estData.data.available_jobs_by_pk.est_data + ) + ) { + //We don't have the right data. Error! + setInsertLoading(false); + notification["error"]({ + message: t("jobs.errors.creating", { error: "No job data present." }) + }); + } else { + insertNewJob({ + variables: { + job: selectedOwner + ? Object.assign( + {}, + estData.data.available_jobs_by_pk.est_data, + { owner: null }, + { ownerid: selectedOwner } + ) + : estData.data.available_jobs_by_pk.est_data + } + }) + .then(r => { + notification["success"]({ + message: t("jobs.successes.created"), + onClick: () => { + console.log("r", r); + history.push( + `/manage/jobs/${r.data.insert_jobs.returning[0].id}` + ); + } + }); + //Job has been inserted. Clean up the available jobs record. + deleteJob({ + variables: { id: estData.data.available_jobs_by_pk.id } + }).then(r => { + refetch(); + setInsertLoading(false); + }); + }) + .catch(r => { + //error while inserting + notification["error"]({ + message: t("jobs.errors.creating", { error: r.message }) + }); + refetch(); + setInsertLoading(false); + }); + } }; - const onModalCancel = () => setModalVisible(false); + const onModalCancel = () => { + setModalVisible(false); + setSelectedOwner(null); + }; if (error) return ; return ( - + + + ); -} +}); diff --git a/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx b/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx index 4d8148ac6..b9da502d5 100644 --- a/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx +++ b/client/src/components/jobs-detail-header/jobs-detail-header.component.jsx @@ -1,4 +1,12 @@ -import { Avatar, Button, Checkbox, Descriptions, notification, PageHeader, Tag } from "antd"; +import { + Avatar, + Button, + Checkbox, + Descriptions, + notification, + PageHeader, + Tag +} from "antd"; import React from "react"; import { useTranslation } from "react-i18next"; import Moment from "react-moment"; @@ -16,7 +24,7 @@ export default function JobsDetailHeader({ const tombstoneTitle = (
- + {`${t("jobs.fields.ro_number")} ${ job.ro_number ? job.ro_number : t("general.labels.na") }`} @@ -25,26 +33,34 @@ export default function JobsDetailHeader({ const tombstoneSubtitle = (
- {job.owner - ? (job.owner.first_name || "") + " " + (job.owner.last_name || "") - : t("jobs.errors.noowner")} + + {job.owner ? ( + + {`${job.ownr_co_nm || ""}${job.ownr_fn || ""} ${job.ownr_ln || ""}`} + + ) : ( + t("jobs.errors.noowner") + )} + - {job.vehicle ? ( - - {job.vehicle.v_model_yr || t("general.labels.na")}{" "} - {job.vehicle.v_make_desc || t("general.labels.na")}{" "} - {job.vehicle.v_model_desc || t("general.labels.na")} |{" "} - {job.vehicle.plate_no || t("general.labels.na")} |{" "} - {job.vehicle.v_vin || t("general.labels.na")} - - ) : null} + + {job.vehicle ? ( + + {job.vehicle.v_model_yr || t("general.labels.na")}{" "} + {job.vehicle.v_make_desc || t("general.labels.na")}{" "} + {job.vehicle.v_model_desc || t("general.labels.na")} |{" "} + {job.vehicle.plate_no || t("general.labels.na")} |{" "} + {job.vehicle.v_vin || t("general.labels.na")} + + ) : null} +
); const menuExtra = [ , - ]; @@ -72,14 +89,15 @@ export default function JobsDetailHeader({ title={tombstoneTitle} subTitle={tombstoneSubtitle} tags={ - + {job.job_status ? ( - {job.job_status.name} + {job.job_status.name} ) : null} } - extra={menuExtra}> - + extra={menuExtra} + > + {job.claim_total} @@ -94,7 +112,7 @@ export default function JobsDetailHeader({ {job.scheduled_completion ? ( - {job.scheduled_completion} + {job.scheduled_completion} ) : null} diff --git a/client/src/components/loading-spinner/loading-spinner.component.jsx b/client/src/components/loading-spinner/loading-spinner.component.jsx index 94c35d8b0..98ab9e422 100644 --- a/client/src/components/loading-spinner/loading-spinner.component.jsx +++ b/client/src/components/loading-spinner/loading-spinner.component.jsx @@ -2,6 +2,16 @@ import React from "react"; import { Spin } from "antd"; import "./loading-spinner.styles.scss"; -export default function LoadingSpinner() { - return ; +export default function LoadingSpinner({ loading = true, message, ...props }) { + return ( + + {props.children} + + ); } diff --git a/client/src/components/owner-find-modal/owner-find-modal.component.jsx b/client/src/components/owner-find-modal/owner-find-modal.component.jsx index c06b10d09..c9631e54b 100644 --- a/client/src/components/owner-find-modal/owner-find-modal.component.jsx +++ b/client/src/components/owner-find-modal/owner-find-modal.component.jsx @@ -1,4 +1,4 @@ -import { Table, Checkbox, Divider } from "antd"; +import { Checkbox, Divider, Table } from "antd"; import React from "react"; import { useTranslation } from "react-i18next"; import PhoneFormatter from "../../utils/PhoneFormatter"; @@ -98,17 +98,18 @@ export default function OwnerFindModalComponent({ rowKey="id" loading={ownersListLoading} dataSource={ownersList} - //onChange={handleTableChange} - rowSelection={{ selectedRowKeys: [selectedOwner] }} + rowSelection={{ + onSelect: props => { + setSelectedOwner(props.id); + }, + type: "radio", + selectedRowKeys: [selectedOwner] + }} onRow={(record, rowIndex) => { return { onClick: event => { handleOnRowClick(record); - }, // click row - onDoubleClick: event => {}, // double click row - onContextMenu: event => {}, // right button click row - onMouseEnter: event => {}, // mouse enter row - onMouseLeave: event => {} // mouse leave row + } }; }} /> diff --git a/client/src/components/owner-find-modal/owner-find-modal.container.jsx b/client/src/components/owner-find-modal/owner-find-modal.container.jsx index 8aa84c97e..bd12e1559 100644 --- a/client/src/components/owner-find-modal/owner-find-modal.container.jsx +++ b/client/src/components/owner-find-modal/owner-find-modal.container.jsx @@ -1,11 +1,11 @@ import { Modal } from "antd"; import React from "react"; +import { useQuery } from "react-apollo"; +import { useTranslation } from "react-i18next"; +import { QUERY_SEARCH_OWNER_BY_IDX } from "../../graphql/owners.queries"; import AlertComponent from "../alert/alert.component"; import LoadingSpinner from "../loading-spinner/loading-spinner.component"; import OwnerFindModalComponent from "./owner-find-modal.component"; -import { useQuery } from "react-apollo"; -import { QUERY_SEARCH_OWNER_BY_IDX } from "../../graphql/owners.queries"; -import { useTranslation } from "react-i18next"; export default function OwnerFindModalContainer({ loading, diff --git a/client/src/graphql/jobs.queries.js b/client/src/graphql/jobs.queries.js index 2a69f727d..5bffe873d 100644 --- a/client/src/graphql/jobs.queries.js +++ b/client/src/graphql/jobs.queries.js @@ -152,6 +152,13 @@ export const GET_JOB_BY_PK = gql` towing_payable storage_payable adjustment_bottom_line + ownr_fn + ownr_ln + owner{ + id + ownr_fn + ownr_ln + } } } `; diff --git a/client/src/translations/en_us/common.json b/client/src/translations/en_us/common.json index 4a1dbf7ee..e7cd16153 100644 --- a/client/src/translations/en_us/common.json +++ b/client/src/translations/en_us/common.json @@ -46,6 +46,7 @@ "printCenter": "Print Center" }, "errors": { + "creating": "Error encountered while creating job. {{error}}", "deleted": "Error deleting job.", "noaccess": "This job does not exist or you do not have access to it.", "nodates": "No dates specified for this job.", @@ -127,6 +128,7 @@ "vehicle": "Vehicle" }, "labels": { + "available_new_jobs": "", "cards": { "appraiser": "Appraiser", "customer": "Customer Information", @@ -141,6 +143,7 @@ "totals": "Totals", "vehicle": "Vehicle" }, + "creating_new_job": "Creating new job...", "documents": "Documents", "lines": "Estimate Lines", "notes": "Notes", @@ -151,7 +154,7 @@ "successes": { "all_deleted": "{{count}} jobs deleted successfully.", "converted": "Job converted successfully.", - "created": "Job created successfully.", + "created": "Job created successfully. Click to view.", "deleted": "Job deleted successfully.", "save": "Record Saved", "savetitle": "Record saved successfully." diff --git a/client/src/translations/es/common.json b/client/src/translations/es/common.json index f96467bc5..b476ac6d5 100644 --- a/client/src/translations/es/common.json +++ b/client/src/translations/es/common.json @@ -46,6 +46,7 @@ "printCenter": "Centro de impresión" }, "errors": { + "creating": "", "deleted": "Error al eliminar el trabajo.", "noaccess": "Este trabajo no existe o no tiene acceso a él.", "nodates": "No hay fechas especificadas para este trabajo.", @@ -127,6 +128,7 @@ "vehicle": "Vehículo" }, "labels": { + "available_new_jobs": "", "cards": { "appraiser": "Tasador", "customer": "Información al cliente", @@ -141,6 +143,7 @@ "totals": "Totales", "vehicle": "Vehículo" }, + "creating_new_job": "Creando nuevo trabajo ...", "documents": "documentos", "lines": "Líneas estimadas", "notes": "Notas", @@ -151,7 +154,7 @@ "successes": { "all_deleted": "{{count}} trabajos eliminados con éxito.", "converted": "Trabajo convertido con éxito.", - "created": "Trabajo creado con éxito.", + "created": "Trabajo creado con éxito. Click para ver.", "deleted": "Trabajo eliminado con éxito.", "save": "Registro guardado", "savetitle": "Registro guardado con éxito." diff --git a/client/src/translations/fr/common.json b/client/src/translations/fr/common.json index 685489712..98c79b11d 100644 --- a/client/src/translations/fr/common.json +++ b/client/src/translations/fr/common.json @@ -46,6 +46,7 @@ "printCenter": "Centre d'impression" }, "errors": { + "creating": "", "deleted": "Erreur lors de la suppression du travail.", "noaccess": "Ce travail n'existe pas ou vous n'y avez pas accès.", "nodates": "Aucune date spécifiée pour ce travail.", @@ -127,6 +128,7 @@ "vehicle": "Véhicule" }, "labels": { + "available_new_jobs": "", "cards": { "appraiser": "Expert", "customer": "Informations client", @@ -141,6 +143,7 @@ "totals": "Totaux", "vehicle": "Véhicule" }, + "creating_new_job": "Création d'un nouvel emploi ...", "documents": "Les documents", "lines": "Estimer les lignes", "notes": "Remarques", @@ -151,7 +154,7 @@ "successes": { "all_deleted": "{{count}} travaux supprimés avec succès.", "converted": "Travail converti avec succès.", - "created": "Le travail a été créé avec succès.", + "created": "Le travail a été créé avec succès. Clique pour voir.", "deleted": "Le travail a bien été supprimé.", "save": "Enregistrement enregistré", "savetitle": "Enregistrement enregistré avec succès." diff --git a/hasura/migrations/1580332913585_alter_table_public_owners_add_column_ownr_title/down.yaml b/hasura/migrations/1580332913585_alter_table_public_owners_add_column_ownr_title/down.yaml new file mode 100644 index 000000000..ca71eb499 --- /dev/null +++ b/hasura/migrations/1580332913585_alter_table_public_owners_add_column_ownr_title/down.yaml @@ -0,0 +1,3 @@ +- args: + sql: ALTER TABLE "public"."owners" DROP COLUMN "ownr_title"; + type: run_sql diff --git a/hasura/migrations/1580332913585_alter_table_public_owners_add_column_ownr_title/up.yaml b/hasura/migrations/1580332913585_alter_table_public_owners_add_column_ownr_title/up.yaml new file mode 100644 index 000000000..be8c2ce7b --- /dev/null +++ b/hasura/migrations/1580332913585_alter_table_public_owners_add_column_ownr_title/up.yaml @@ -0,0 +1,3 @@ +- args: + sql: ALTER TABLE "public"."owners" ADD COLUMN "ownr_title" text NULL; + type: run_sql diff --git a/hasura/migrations/1580332923811_update_permission_user_public_table_owners/down.yaml b/hasura/migrations/1580332923811_update_permission_user_public_table_owners/down.yaml new file mode 100644 index 000000000..55880362e --- /dev/null +++ b/hasura/migrations/1580332923811_update_permission_user_public_table_owners/down.yaml @@ -0,0 +1,45 @@ +- args: + role: user + table: + name: owners + schema: public + type: drop_insert_permission +- args: + permission: + check: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - id + - created_at + - updated_at + - ownr_fn + - ownr_ln + - ownr_addr1 + - ownr_addr2 + - ownr_city + - ownr_st + - ownr_zip + - ownr_ctry + - ownr_ea + - ownr_ph1 + - preferred_contact + - allow_text_message + - shopid + - ownr_ph2 + - ownr_co_nm + localPresets: + - key: "" + value: "" + set: {} + role: user + table: + name: owners + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1580332923811_update_permission_user_public_table_owners/up.yaml b/hasura/migrations/1580332923811_update_permission_user_public_table_owners/up.yaml new file mode 100644 index 000000000..21addc58a --- /dev/null +++ b/hasura/migrations/1580332923811_update_permission_user_public_table_owners/up.yaml @@ -0,0 +1,46 @@ +- args: + role: user + table: + name: owners + schema: public + type: drop_insert_permission +- args: + permission: + check: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + columns: + - id + - created_at + - updated_at + - ownr_fn + - ownr_ln + - ownr_addr1 + - ownr_addr2 + - ownr_city + - ownr_st + - ownr_zip + - ownr_ctry + - ownr_ea + - ownr_ph1 + - preferred_contact + - allow_text_message + - shopid + - ownr_ph2 + - ownr_co_nm + - ownr_title + localPresets: + - key: "" + value: "" + set: {} + role: user + table: + name: owners + schema: public + type: create_insert_permission diff --git a/hasura/migrations/1580332931020_update_permission_user_public_table_owners/down.yaml b/hasura/migrations/1580332931020_update_permission_user_public_table_owners/down.yaml new file mode 100644 index 000000000..1802dbbf4 --- /dev/null +++ b/hasura/migrations/1580332931020_update_permission_user_public_table_owners/down.yaml @@ -0,0 +1,43 @@ +- args: + role: user + table: + name: owners + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - allow_text_message + - ownr_addr1 + - ownr_addr2 + - ownr_city + - ownr_co_nm + - ownr_ctry + - ownr_ea + - ownr_fn + - ownr_ln + - ownr_ph1 + - ownr_ph2 + - ownr_st + - ownr_zip + - preferred_contact + - created_at + - updated_at + - id + - shopid + computed_fields: [] + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: owners + schema: public + type: create_select_permission diff --git a/hasura/migrations/1580332931020_update_permission_user_public_table_owners/up.yaml b/hasura/migrations/1580332931020_update_permission_user_public_table_owners/up.yaml new file mode 100644 index 000000000..85ab7c994 --- /dev/null +++ b/hasura/migrations/1580332931020_update_permission_user_public_table_owners/up.yaml @@ -0,0 +1,44 @@ +- args: + role: user + table: + name: owners + schema: public + type: drop_select_permission +- args: + permission: + allow_aggregations: false + columns: + - allow_text_message + - ownr_addr1 + - ownr_addr2 + - ownr_city + - ownr_co_nm + - ownr_ctry + - ownr_ea + - ownr_fn + - ownr_ln + - ownr_ph1 + - ownr_ph2 + - ownr_st + - ownr_title + - ownr_zip + - preferred_contact + - created_at + - updated_at + - id + - shopid + computed_fields: [] + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + role: user + table: + name: owners + schema: public + type: create_select_permission diff --git a/hasura/migrations/1580332936658_update_permission_user_public_table_owners/down.yaml b/hasura/migrations/1580332936658_update_permission_user_public_table_owners/down.yaml new file mode 100644 index 000000000..26c35bd8f --- /dev/null +++ b/hasura/migrations/1580332936658_update_permission_user_public_table_owners/down.yaml @@ -0,0 +1,45 @@ +- args: + role: user + table: + name: owners + schema: public + type: drop_update_permission +- args: + permission: + columns: + - allow_text_message + - ownr_addr1 + - ownr_addr2 + - ownr_city + - ownr_co_nm + - ownr_ctry + - ownr_ea + - ownr_fn + - ownr_ln + - ownr_ph1 + - ownr_ph2 + - ownr_st + - ownr_zip + - preferred_contact + - created_at + - updated_at + - id + - shopid + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + localPresets: + - key: "" + value: "" + set: {} + role: user + table: + name: owners + schema: public + type: create_update_permission diff --git a/hasura/migrations/1580332936658_update_permission_user_public_table_owners/up.yaml b/hasura/migrations/1580332936658_update_permission_user_public_table_owners/up.yaml new file mode 100644 index 000000000..9609517ec --- /dev/null +++ b/hasura/migrations/1580332936658_update_permission_user_public_table_owners/up.yaml @@ -0,0 +1,46 @@ +- args: + role: user + table: + name: owners + schema: public + type: drop_update_permission +- args: + permission: + columns: + - allow_text_message + - ownr_addr1 + - ownr_addr2 + - ownr_city + - ownr_co_nm + - ownr_ctry + - ownr_ea + - ownr_fn + - ownr_ln + - ownr_ph1 + - ownr_ph2 + - ownr_st + - ownr_title + - ownr_zip + - preferred_contact + - created_at + - updated_at + - id + - shopid + filter: + bodyshop: + associations: + _and: + - user: + authid: + _eq: X-Hasura-User-Id + - active: + _eq: true + localPresets: + - key: "" + value: "" + set: {} + role: user + table: + name: owners + schema: public + type: create_update_permission