Skip to content
This repository was archived by the owner on Apr 2, 2024. It is now read-only.

Commit

Permalink
Change service port select label when subscription has title (#269)
Browse files Browse the repository at this point in the history
* Change service port select label when response has title

* remove accidental double }

* Update ContactPersonNameField to be compatible with customer change
  • Loading branch information
tjeerddie authored Feb 7, 2024
1 parent ed72a99 commit dabdbf9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/custom-surf/uniforms/ContactPersonNameField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,20 @@ import ApplicationContext from "utils/ApplicationContext";
import { ContactPerson } from "utils/types";
import { stop } from "utils/Utils";

export type ContactPersonNameFieldProps = FieldProps<string, { organisationId?: string; organisationKey?: string }>;
export type ContactPersonNameFieldProps = FieldProps<
string,
{ customerId?: string; customerKey?: string; organisationId?: string; organisationKey?: string }
>;

declare module "uniforms" {
interface FilterDOMProps {
organisationId: never;
organisationKey: never;
customerId: never;
customerKey: never;
organistionId: never;
organistionKey: never;
}
}
filterDOMProps.register("organisationId", "organisationKey");
filterDOMProps.register("customerId", "customerKey", "organistionId", "organistionKey");

function ContactPersonName({
disabled,
Expand All @@ -49,10 +54,19 @@ function ContactPersonName({
error,
showInlineError,
errorMessage,
customerId,
customerKey,
organisationId,
organisationKey,
...props
}: ContactPersonNameFieldProps) {
if (organisationId) {
customerId = organisationId;
}
if (organisationKey) {
customerKey = organisationKey;
}

const intl = useIntl();
const { customApiClient } = useContext(ApplicationContext);
const { model, onChange: formOnChange, schema } = useForm();
Expand All @@ -67,19 +81,17 @@ function ContactPersonName({
const useFieldName = contactsPersonFieldNameArray.length ? contactsFieldName : name;
const contactsField = useField(useFieldName, {}, { absoluteName: true })[0];

const organisationFieldName = organisationKey || contactsField.field.organisationKey || "organisation";
const customerFieldName = customerKey || contactsField.field.customerKey || "customer_id";

// Get initial value for org field if it exists (we cant really test)
let organisationInitialValue;
let customerInitialValue;
try {
organisationInitialValue = schema.getInitialValue(organisationFieldName, {});
customerInitialValue = schema.getInitialValue(customerFieldName, {});
} catch {
organisationInitialValue = "";
customerInitialValue = "";
}
const organisationIdValue =
organisationId ||
contactsField.field.organisationId ||
get(model, organisationFieldName, organisationInitialValue);
const customerIdValue =
customerId || contactsField.field.customerId || get(model, customerFieldName, customerInitialValue);

let [displayAutocomplete, setDisplayAutocomplete] = useState(false);
let [contactPersons, setContactPersons] = useState<ContactPerson[]>([]);
Expand All @@ -92,12 +104,12 @@ function ContactPersonName({
: [];

useEffect(() => {
if (organisationIdValue) {
customApiClient.contacts(organisationIdValue).then((contactPersons) => {
if (customerIdValue) {
customApiClient.contacts(customerIdValue).then((contactPersons) => {
setContactPersons(contactPersons);
});
}
}, [organisationIdValue, customApiClient]);
}, [customerIdValue, customApiClient]);

useEffect(() => {
// Set focus to the last name component to be created
Expand Down
3 changes: 3 additions & 0 deletions src/lib/uniforms-surfnet/src/SubscriptionField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export function makeLabel(subscription: iSubscription, products: Product[], orga
} else if (["SP", "SPNL", "AGGSP", "AGGSPNL", "MSC", "MSCNL", "IRBSP"].includes(product.tag)) {
let portSubscription = subscription as ServicePortSubscription;
const portMode = getPortMode(portSubscription, products);
if (portSubscription.title) {
return `${subscription_substring} - ${description.trim()} - ${portSubscription.title.trim()}`;
}
return `${subscription_substring} ${portMode.toUpperCase()} ${description.trim()} ${customerName}`;
} else {
return description.trim();
Expand Down
1 change: 1 addition & 0 deletions src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export interface IpPrefixSubscription extends Subscription {

export interface ServicePortSubscription extends Subscription {
port_mode?: string;
title?: string;
}

export interface ServicePort {
Expand Down

0 comments on commit dabdbf9

Please sign in to comment.