Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show latest form fields changes for local unit validations #1589

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/src/components/domain/BaseMapPointInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ interface Props<NAME> extends BaseMapProps {
readOnly?: boolean;
required?: boolean;
error?: ObjectError<Value>;
baseMapFormFieldsChanges: {
lat: boolean | undefined;
lng: boolean | undefined;
} | undefined;
}

function BaseMapPointInput<NAME extends string>(props: Props<NAME>) {
Expand All @@ -74,6 +78,7 @@ function BaseMapPointInput<NAME extends string>(props: Props<NAME>) {
country,
required,
error,
baseMapFormFieldsChanges,
...otherProps
} = props;

Expand Down Expand Up @@ -183,6 +188,10 @@ function BaseMapPointInput<NAME extends string>(props: Props<NAME>) {
<div className={_cs(styles.baseMapPointInput, className)}>
<div className={styles.locationInputs}>
<NumberInput
inputSectionClassName={_cs(
baseMapFormFieldsChanges?.lat
&& styles.changes,
)}
className={styles.input}
name="lat"
label={strings.latitude}
Expand All @@ -193,6 +202,10 @@ function BaseMapPointInput<NAME extends string>(props: Props<NAME>) {
required={required}
/>
<NumberInput
inputSectionClassName={_cs(
baseMapFormFieldsChanges?.lng
&& styles.changes,
)}
className={styles.input}
name="lng"
label={strings.longitude}
Expand Down
4 changes: 4 additions & 0 deletions app/src/components/domain/BaseMapPointInput/styles.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
flex-direction: column;
gap: var(--go-ui-spacing-md);

.changes {
background-color: var(--go-ui-color-semantic-yellow) !important;
}

.location-inputs {
display: flex;
gap: var(--go-ui-spacing-sm);
Expand Down
23 changes: 18 additions & 5 deletions app/src/utils/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { DEFAULT_INVALID_TEXT } from '@ifrc-go/ui/utils';
import { isTruthyString } from '@togglecorp/fujs';
import {
isDefined,
isNotDefined,
isTruthyString,
} from '@togglecorp/fujs';

import type { GoApiResponse } from '#utils/restRequest';

Expand Down Expand Up @@ -54,11 +58,20 @@ export function getFirstTruthyString(
}

// TODO: write tests for the function
export function doArraysContainSameElements(newArray: unknown[], oldArray: unknown[]): boolean {
if (newArray.length !== oldArray.length) {
return false;
export function doArraysContainSameElements(
newArray: unknown[] | undefined,
oldArray: unknown[] | undefined,
): boolean {
if (isNotDefined(newArray) && isNotDefined(oldArray)) {
return true;
}
return newArray.every((id) => oldArray.includes(id));
if (isDefined(newArray) && isDefined(oldArray)) {
if (newArray.length !== oldArray.length) {
return false;
}
return newArray.every((id) => oldArray.includes(id));
}
return false;
}

// TODO: write tests for the function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
"revertChangesModalHeading": "Revert the Changes",
"revertChangesContentQuestion": "Are you sure you want to have these changes revert in this project?",
"confirmChangesModalHeading": "Confirm the Changes",
"confirmChangesContentQuestion": "Are you sure you want to have these changes in this project?",
"confirmChangesContentQuestion": "Are you sure you want to have these changes in this local unit?",
"newLocalUnitDescription": "New local unit",
"latitude": "Latitude",
"longitude": "Longitude"
}
Expand Down
Loading
Loading