IO-896 Fleet # Validation
This commit is contained in:
@@ -8,9 +8,13 @@ import FormFieldsChanged from "../form-fields-changed-alert/form-fields-changed-
|
||||
import CurrencyInput from "../form-items-formatted/currency-form-item.component";
|
||||
import LayoutFormRow from "../layout-form-row/layout-form-row.component";
|
||||
import InputNumberCalculator from "../form-input-number-calculator/form-input-number-calculator.component";
|
||||
import { useApolloClient } from "@apollo/client";
|
||||
import { CHECK_CC_FLEET_NUMBER } from "../../graphql/courtesy-car.queries";
|
||||
|
||||
export default function CourtesyCarCreateFormComponent({ form, saveLoading }) {
|
||||
const { t } = useTranslation();
|
||||
const client = useApolloClient();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<PageHeader
|
||||
@@ -117,6 +121,43 @@ export default function CourtesyCarCreateFormComponent({ form, saveLoading }) {
|
||||
<Form.Item
|
||||
label={t("courtesycars.fields.fleetnumber")}
|
||||
name="fleetnumber"
|
||||
validateTrigger="onBlur"
|
||||
hasFeedback
|
||||
rules={[
|
||||
{
|
||||
required: true,
|
||||
message: t("general.validation.required"),
|
||||
},
|
||||
({ getFieldValue }) => ({
|
||||
async validator(rule, value) {
|
||||
if (value) {
|
||||
const response = await client.query({
|
||||
query: CHECK_CC_FLEET_NUMBER,
|
||||
variables: {
|
||||
name: value,
|
||||
},
|
||||
});
|
||||
|
||||
if (
|
||||
response.data.courtesycars_aggregate.aggregate.count === 0
|
||||
) {
|
||||
return Promise.resolve();
|
||||
} else if (
|
||||
response.data.courtesycars_aggregate.nodes.length === 1 &&
|
||||
response.data.courtesycars_aggregate.nodes[0].id ===
|
||||
form.getFieldValue("id")
|
||||
) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return Promise.reject(
|
||||
t("vendors.validation.unique_vendor_name")
|
||||
);
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
},
|
||||
}),
|
||||
]}
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
|
||||
@@ -13,26 +13,45 @@ export const INSERT_NEW_COURTESY_CAR = gql`
|
||||
`;
|
||||
|
||||
export const QUERY_AVAILABLE_CC = gql`
|
||||
query QUERY_AVAILABLE_CC($today: date) {
|
||||
courtesycars(where: {_or: [{serviceenddate: {_is_null: true}}, {serviceenddate: {_gt: $today}}], status: {_eq: "courtesycars.status.in"}}) {
|
||||
color
|
||||
dailycost
|
||||
damage
|
||||
fleetnumber
|
||||
fuel
|
||||
id
|
||||
make
|
||||
model
|
||||
plate
|
||||
status
|
||||
year
|
||||
dailycost
|
||||
mileage
|
||||
query QUERY_AVAILABLE_CC($today: date) {
|
||||
courtesycars(
|
||||
where: {
|
||||
_or: [
|
||||
{ serviceenddate: { _is_null: true } }
|
||||
{ serviceenddate: { _gt: $today } }
|
||||
]
|
||||
status: { _eq: "courtesycars.status.in" }
|
||||
}
|
||||
) {
|
||||
color
|
||||
dailycost
|
||||
damage
|
||||
fleetnumber
|
||||
fuel
|
||||
id
|
||||
make
|
||||
model
|
||||
plate
|
||||
status
|
||||
year
|
||||
dailycost
|
||||
mileage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
`;
|
||||
|
||||
export const CHECK_CC_FLEET_NUMBER = gql`
|
||||
query CHECK_VENDOR_NAME($name: String!) {
|
||||
courtesycars_aggregate(where: { fleetnumber: { _ilike: $name } }) {
|
||||
aggregate {
|
||||
count
|
||||
}
|
||||
nodes {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
export const QUERY_ALL_CC = gql`
|
||||
query QUERY_ALL_CC {
|
||||
courtesycars {
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: courtesycars
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: false
|
||||
columns:
|
||||
- insuranceexpires
|
||||
- leaseenddate
|
||||
- nextservicedate
|
||||
- purchasedate
|
||||
- registrationexpires
|
||||
- serviceenddate
|
||||
- servicestartdate
|
||||
- dailycost
|
||||
- fuel
|
||||
- mileage
|
||||
- nextservicekm
|
||||
- color
|
||||
- damage
|
||||
- fleetnumber
|
||||
- make
|
||||
- model
|
||||
- notes
|
||||
- plate
|
||||
- status
|
||||
- vin
|
||||
- year
|
||||
- created_at
|
||||
- updated_at
|
||||
- bodyshopid
|
||||
- id
|
||||
computed_fields: []
|
||||
filter:
|
||||
bodyshop:
|
||||
associations:
|
||||
_and:
|
||||
- user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
role: user
|
||||
table:
|
||||
name: courtesycars
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -0,0 +1,50 @@
|
||||
- args:
|
||||
role: user
|
||||
table:
|
||||
name: courtesycars
|
||||
schema: public
|
||||
type: drop_select_permission
|
||||
- args:
|
||||
permission:
|
||||
allow_aggregations: true
|
||||
columns:
|
||||
- insuranceexpires
|
||||
- leaseenddate
|
||||
- nextservicedate
|
||||
- purchasedate
|
||||
- registrationexpires
|
||||
- serviceenddate
|
||||
- servicestartdate
|
||||
- dailycost
|
||||
- fuel
|
||||
- mileage
|
||||
- nextservicekm
|
||||
- color
|
||||
- damage
|
||||
- fleetnumber
|
||||
- make
|
||||
- model
|
||||
- notes
|
||||
- plate
|
||||
- status
|
||||
- vin
|
||||
- year
|
||||
- created_at
|
||||
- updated_at
|
||||
- bodyshopid
|
||||
- id
|
||||
computed_fields: []
|
||||
filter:
|
||||
bodyshop:
|
||||
associations:
|
||||
_and:
|
||||
- user:
|
||||
authid:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
role: user
|
||||
table:
|
||||
name: courtesycars
|
||||
schema: public
|
||||
type: create_select_permission
|
||||
@@ -1215,6 +1215,7 @@ tables:
|
||||
_eq: X-Hasura-User-Id
|
||||
- active:
|
||||
_eq: true
|
||||
allow_aggregations: true
|
||||
update_permissions:
|
||||
- role: user
|
||||
permission:
|
||||
|
||||
Reference in New Issue
Block a user