Skip to content

Commit

Permalink
Add new local unit tag in add local unit form modal
Browse files Browse the repository at this point in the history
  • Loading branch information
shreeyash07 authored and samshara committed Dec 20, 2024
1 parent 19b09a0 commit 08c1d9a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"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 local unit?",
"newLocalUnitDescription": "New local unit",
"latitude": "Latitude",
"longitude": "Longitude"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
_cs,
isDefined,
isNotDefined,
isObject,
} from '@togglecorp/fujs';
import {
createSubmitHandler,
Expand Down Expand Up @@ -646,7 +647,7 @@ function LocalUnitsForm(props: Props) {
revertChanges(formValues as LocalUnitsRevertRequestPostBody);
setShowRevertChangesModalFalse();
},
[revertChanges],
[revertChanges, setShowRevertChangesModalFalse],
);

const latestChangesFormFields = useMemo(() => {
Expand Down Expand Up @@ -692,6 +693,8 @@ function LocalUnitsForm(props: Props) {
setShowChangesModalTrue();
},
[
setError,
validate,
setShowChangesModalTrue,
localUnitDetailsResponse,
value,
Expand Down Expand Up @@ -733,6 +736,15 @@ function LocalUnitsForm(props: Props) {
};
}, []);

const isNewLocalUnit = useMemo(() => {
if (isObject(previousData)) {
if (Object.keys(previousData).length <= 0) {
return true;
}
}
return false;
}, [previousData]);

return (
<div className={styles.localUnitsForm}>
{isDefined(localUnitDetailsResponse)
Expand Down Expand Up @@ -769,6 +781,13 @@ function LocalUnitsForm(props: Props) {
{isDefined(headingDescriptionRef) && isDefined(headingDescriptionRef.current) && (
<Portal container={headingDescriptionRef.current}>
<div className={styles.lastUpdateLabel}>
{isNewLocalUnit && (
<TextOutput
className={styles.newLocalUnit}
value={strings.newLocalUnitDescription}
strongValue
/>
)}
{resolveToComponent(
strings.lastUpdateLabel,
{
Expand Down Expand Up @@ -850,7 +869,8 @@ function LocalUnitsForm(props: Props) {
readOnly={!pristine}
/>
)}
{localUnitDetailsResponse.is_locked && isDefined(previousData) && (
{localUnitDetailsResponse.is_locked
&& !isNewLocalUnit && (
<Button
name={undefined}
onClick={setShowRevertChangesModalTrue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@

.last-update-label {
color: var(--go-ui-color-text-light);

.new-local-unit {
color: var(--go-ui-color-positive);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,9 @@ function LocalUnitsMap(props: Props) {
setReadOnly={setReadOnlyLocalUnitModal}
onDeleteActionSuccess={refetchLocalUnits}
previousData={
previousData?.previous_data_details as unknown as LocalUnitResponse
superLocalUnitDetailResponse?.validated
? undefined
: previousData?.previous_data_details as unknown as LocalUnitResponse
}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ function LocalUnitsTableActions(props: Props) {
},
[setShowLocalUnitModalFalse, onDeleteActionSuccess],
);

const handleViewLocalUnitClick = useCallback(
() => {
if (!isValidated) {
Expand Down Expand Up @@ -209,7 +210,9 @@ function LocalUnitsTableActions(props: Props) {
setReadOnly={setReadOnlyLocalUnitModal}
onDeleteActionSuccess={onDeleteActionSuccess}
previousData={
previousData?.previous_data_details as unknown as LocalUnitResponse
isValidated
? undefined
: previousData?.previous_data_details as unknown as LocalUnitResponse
}
/>
)}
Expand Down

0 comments on commit 08c1d9a

Please sign in to comment.