Skip to content

Commit

Permalink
[SDP-703]: Support the edition of the privacy_policy_link (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
ceciliaromao authored Apr 8, 2024
1 parent 5f4fedc commit 9deb6e0
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
16 changes: 11 additions & 5 deletions src/api/patchOrgInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,32 @@ export const patchOrgInfo = async (
}

const formData = new FormData();
let data = {};

Object.entries(fieldsToSubmit).forEach(([key, value]) => {
switch (key) {
case "name":
formData.append("data", `{"organization_name": "${value}"}`);
data = { ...data, organization_name: `${value}` };
break;
case "privacyPolicyLink":
data = { ...data, privacy_policy_link: `${value}` };
break;
case "timezone":
formData.append("data", `{"timezone_utc_offset": "${value}"}`);
data = { ...data, timezone_utc_offset: `${value}` };
break;
case "isApprovalRequired":
data = { ...data, is_approval_required: value };
break;
case "logo":
formData.append("logo", value as Blob);
break;
case "isApprovalRequired":
formData.append("data", `{"is_approval_required": ${value}}`);
break;
default:
throw Error(`Update organization does not accept ${key} field`);
}
});

formData.append("data", `${JSON.stringify(data)}`);

// BE always expects data object
if (!formData.get("data")) {
formData.append("data", "{}");
Expand Down
51 changes: 45 additions & 6 deletions src/pages/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const Profile = () => {
});
const [organizationDetails, setOrganizationDetails] = useState({
name: "",
privacyPolicyLink: "",
logo: "",
});

Expand Down Expand Up @@ -211,7 +212,7 @@ export const Profile = () => {
id: profile.data.id,
firstName: profile.data.firstName,
lastName: profile.data.lastName,
email: profile.data.lastName,
email: profile.data.email,
role: profile.data.role,
});
dispatch(clearErrorAction());
Expand All @@ -222,13 +223,22 @@ export const Profile = () => {
) => {
event.preventDefault();

if (organizationDetails.name || imageFile || isApprovalRequired) {
if (
organizationDetails.name ||
organizationDetails.privacyPolicyLink ||
imageFile ||
isApprovalRequired
) {
dispatch(
updateOrgInfoAction({
name: emptyValueIfNotChanged(
organizationDetails.name,
organization.data.name,
),
privacyPolicyLink: emptyValueIfNotChanged(
organizationDetails.privacyPolicyLink,
organization.data.privacyPolicyLink,
),
logo: imageFile,
isApprovalRequired,
}),
Expand All @@ -244,6 +254,7 @@ export const Profile = () => {
setImageFile(undefined);
setOrganizationDetails({
name: organization.data.name,
privacyPolicyLink: organization.data.privacyPolicyLink,
logo: organization.data.logo,
});
setIsApprovalRequired(Boolean(organization.data.isApprovalRequired));
Expand Down Expand Up @@ -416,7 +427,7 @@ export const Profile = () => {
: {})}
>
{isEditOrganization ? (
<>
<div className="CardStack__grid">
<Input
id="name"
name="name"
Expand All @@ -425,16 +436,41 @@ export const Profile = () => {
value={organizationDetails.name}
onChange={handleOrgDetailsChange}
/>
</>

<Input
id="privacyPolicyLink"
name="privacyPolicyLink"
label="Privacy Policy Link"
fieldSize="sm"
value={organizationDetails.privacyPolicyLink}
onChange={handleOrgDetailsChange}
/>
</div>
) : (
<>
<div className="CardStack__grid">
<div className="CardStack__infoItem">
<label className="Label Label--sm">Name</label>
<div className="CardStack__infoItem__value">
{organization.data.name}
</div>
</div>
</>

<div className="CardStack__infoItem">
<label className="Label Label--sm">Privacy Policy Link</label>
<div className="CardStack__infoItem__value">
{organization.data.privacyPolicyLink ? (
<Link
href={organization.data.privacyPolicyLink}
target="_blank"
>
{organization.data.privacyPolicyLink}
</Link>
) : (
"-"
)}
</div>
</div>
</div>
)}
<div className="Label Label--sm">
<InfoTooltip
Expand Down Expand Up @@ -471,6 +507,8 @@ export const Profile = () => {
type="submit"
disabled={
organizationDetails.name === organization.data.name &&
organizationDetails.privacyPolicyLink ===
organization.data.privacyPolicyLink &&
!imageFile &&
isApprovalRequired === organization.data.isApprovalRequired
}
Expand Down Expand Up @@ -584,6 +622,7 @@ export const Profile = () => {
setIsEditOrganization(true);
setOrganizationDetails({
name: organization.data.name,
privacyPolicyLink: organization.data.privacyPolicyLink,
logo: organization.data.logo,
});
setIsApprovalRequired(
Expand Down
5 changes: 4 additions & 1 deletion src/store/ducks/organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ export const updateOrgInfoAction = createAsyncThunk<
>(
"organization/updateOrgInfoAction",
async (
{ name, timezone, logo, isApprovalRequired },
{ name, privacyPolicyLink, timezone, logo, isApprovalRequired },
{ rejectWithValue, getState, dispatch },
) => {
const { token } = getState().userAccount;

try {
const orgInfo = await patchOrgInfo(token, {
name,
privacyPolicyLink,
timezone,
logo,
isApprovalRequired,
Expand Down Expand Up @@ -127,6 +128,7 @@ export const getStellarAccountAction = createAsyncThunk<
const initialState: OrganizationInitialState = {
data: {
name: "",
privacyPolicyLink: "",
logo: "",
distributionAccountPublicKey: "",
timezoneUtcOffset: "",
Expand Down Expand Up @@ -164,6 +166,7 @@ const organizationSlice = createSlice({
state.data = {
...state.data,
name: action.payload.name,
privacyPolicyLink: action.payload.privacy_policy_link,
distributionAccountPublicKey:
action.payload.distribution_account_public_key,
timezoneUtcOffset: action.payload.timezone_utc_offset,
Expand Down
3 changes: 3 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export type DisbursementDetailsInitialState = {
export type OrganizationInitialState = {
data: {
name: string;
privacyPolicyLink: string;
logo: string;
distributionAccountPublicKey: string;
timezoneUtcOffset: string;
Expand Down Expand Up @@ -447,6 +448,7 @@ export type AccountProfile = {
// =============================================================================
export type OrgUpdateInfo = {
name?: string;
privacyPolicyLink?: string;
timezone?: string;
logo?: File;
isApprovalRequired?: boolean;
Expand Down Expand Up @@ -761,6 +763,7 @@ export type ApiProfileInfo = {

export type ApiOrgInfo = {
name: string;
privacy_policy_link: string;
logo_url: string;
distribution_account_public_key: string;
timezone_utc_offset: string;
Expand Down

0 comments on commit 9deb6e0

Please sign in to comment.