Skip to content

Commit d7968d3

Browse files
authored
Merge pull request #1506 from salabh-aot/refactor-project-special-fields
Refactor project special fields
2 parents b8a68f7 + 6b25b8e commit d7968d3

File tree

3 files changed

+205
-162
lines changed

3 files changed

+205
-162
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import React from "react";
2+
import { SpecialFieldGrid } from "../../shared/specialField";
3+
import {
4+
SPECIAL_FIELDS,
5+
SpecialFieldEntityEnum,
6+
} from "../../../constants/application-constant";
7+
import { ETCaption3 } from "../../shared";
8+
import { Grid } from "@mui/material";
9+
import { When } from "react-if";
10+
import { SpecialFieldLock } from "../../shared/specialField/components/SpecialFieldLock";
11+
12+
interface ProjectNameSpecialFieldProps {
13+
id: number;
14+
onSave: () => void;
15+
open: boolean;
16+
onLockClick: () => void;
17+
children?: React.ReactNode;
18+
title: string;
19+
}
20+
export const ProjectNameSpecialField = ({
21+
id,
22+
onSave,
23+
open = false,
24+
onLockClick,
25+
children,
26+
title,
27+
}: ProjectNameSpecialFieldProps) => {
28+
return (
29+
<>
30+
<Grid item xs={6}>
31+
<SpecialFieldLock
32+
id={id}
33+
open={open}
34+
onLockClick={onLockClick}
35+
label={"Name"}
36+
required
37+
/>
38+
{children}
39+
</Grid>
40+
<When condition={open}>
41+
<Grid item xs={12}>
42+
<SpecialFieldGrid
43+
entity={SpecialFieldEntityEnum.PROJECT}
44+
entity_id={id}
45+
fieldName={SPECIAL_FIELDS.PROJECT.NAME}
46+
fieldLabel={"Name"}
47+
fieldType={"text"}
48+
title={title}
49+
description={
50+
<ETCaption3>
51+
Update the legal name of the Project and the dates each name was
52+
in legal use. <a href="#">Click this link</a> for detailed
53+
instructions.
54+
</ETCaption3>
55+
}
56+
onSave={onSave}
57+
/>
58+
</Grid>
59+
</When>
60+
</>
61+
);
62+
};
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import React, { useMemo } from "react";
2+
import { SpecialFieldGrid } from "../../shared/specialField";
3+
import {
4+
SPECIAL_FIELDS,
5+
SpecialFieldEntityEnum,
6+
} from "../../../constants/application-constant";
7+
import { ETCaption3 } from "../../shared";
8+
import { Grid } from "@mui/material";
9+
import { When } from "react-if";
10+
import { Proponent } from "../../../models/proponent";
11+
import { SpecialFieldLock } from "../../shared/specialField/components/SpecialFieldLock";
12+
13+
interface ProponentSpecialFieldProps {
14+
id: number;
15+
options: Proponent[];
16+
onSave: () => void;
17+
open: boolean;
18+
onLockClick: () => void;
19+
children?: React.ReactNode;
20+
}
21+
export const ProponentSpecialField = ({
22+
id,
23+
onSave,
24+
open = false,
25+
onLockClick,
26+
options,
27+
children,
28+
}: ProponentSpecialFieldProps) => {
29+
const selectOptions = useMemo(() => {
30+
return options.map((option) => ({
31+
label: option.name,
32+
value: String(option.id),
33+
}));
34+
}, [options]);
35+
36+
return (
37+
<>
38+
<Grid item xs={6}>
39+
<SpecialFieldLock
40+
id={id}
41+
open={open}
42+
onLockClick={onLockClick}
43+
label={"Proponent"}
44+
required
45+
/>
46+
{children}
47+
</Grid>
48+
<When condition={open}>
49+
<Grid item xs={12}>
50+
<SpecialFieldGrid
51+
entity={SpecialFieldEntityEnum.PROJECT}
52+
entity_id={id}
53+
fieldName={SPECIAL_FIELDS.PROJECT.PROPONENT}
54+
fieldLabel={"Proponent Name"}
55+
fieldType={"select"}
56+
title={"Proponent History"}
57+
description={
58+
<ETCaption3>
59+
Update the Proponent of this Project.{" "}
60+
<a href="#">Click this link</a> for detailed instructions.
61+
</ETCaption3>
62+
}
63+
options={selectOptions}
64+
onSave={onSave}
65+
/>
66+
</Grid>
67+
</When>
68+
</>
69+
);
70+
};

0 commit comments

Comments
 (0)