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

project: Update Local Unit edit, validation, and delete workflow #1593

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 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
43 changes: 42 additions & 1 deletion 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 @@ -52,3 +56,40 @@ export function getFirstTruthyString(

return invalidText;
}

// TODO: write tests for the function
export function doArraysContainSameElements(
newArray: unknown[] | undefined,
oldArray: unknown[] | undefined,
): boolean {
if (isNotDefined(newArray) && isNotDefined(oldArray)) {
return true;
}
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
export function flattenObject<T extends Record<string, unknown>>(
inputObject: T,
prefix?: string,
): Record<string, unknown> {
return Object.entries(inputObject).reduce((acc, [key, value]) => {
const newKey = prefix ? `${prefix}.${key}` : key;
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
return { ...acc, ...flattenObject(value as Record<string, unknown>, newKey) };
}
return { ...acc, [newKey]: value };
}, {} as Record<string, unknown>);
}

// TODO: write tests for the function
export function getLastSegment(str: string, delimiter: string) {
const parts = str.split(delimiter);
return parts[parts.length - 1];
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"namespace": "localUnitDeleteModal",
"strings": {
"submitLabel": "Submit",
"deleteSuccessMessage": "{localUnitName} has been successfully deleted.",
"deleteFailureMessage": "Unable to delete {localUnitName}. Please try again.",
"chooseDeleteReasonMessage": "Choose the reason to delete local unit.",
"deleteReasonExplanation": "Explain the reason why the local unit is being deleted.",
"deleteLocalUnitHeading": "Are you sure you want to delete \"{localUnitName}\"?"
}
}
Loading
Loading