diff --git a/src/api/patchOrgInfo.ts b/src/api/patchOrgInfo.ts index dd49e87..bbd7ea0 100644 --- a/src/api/patchOrgInfo.ts +++ b/src/api/patchOrgInfo.ts @@ -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", "{}"); diff --git a/src/pages/Profile.tsx b/src/pages/Profile.tsx index 6bead41..845c19b 100644 --- a/src/pages/Profile.tsx +++ b/src/pages/Profile.tsx @@ -65,6 +65,7 @@ export const Profile = () => { }); const [organizationDetails, setOrganizationDetails] = useState({ name: "", + privacyPolicyLink: "", logo: "", }); @@ -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()); @@ -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, }), @@ -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)); @@ -416,7 +427,7 @@ export const Profile = () => { : {})} > {isEditOrganization ? ( - <> +
{ value={organizationDetails.name} onChange={handleOrgDetailsChange} /> - + + +
) : ( - <> +
{organization.data.name}
- + +
+ +
+ {organization.data.privacyPolicyLink ? ( + + {organization.data.privacyPolicyLink} + + ) : ( + "-" + )} +
+
+
)}
{ type="submit" disabled={ organizationDetails.name === organization.data.name && + organizationDetails.privacyPolicyLink === + organization.data.privacyPolicyLink && !imageFile && isApprovalRequired === organization.data.isApprovalRequired } @@ -584,6 +622,7 @@ export const Profile = () => { setIsEditOrganization(true); setOrganizationDetails({ name: organization.data.name, + privacyPolicyLink: organization.data.privacyPolicyLink, logo: organization.data.logo, }); setIsApprovalRequired( diff --git a/src/store/ducks/organization.ts b/src/store/ducks/organization.ts index 297d207..595e7a3 100644 --- a/src/store/ducks/organization.ts +++ b/src/store/ducks/organization.ts @@ -49,7 +49,7 @@ export const updateOrgInfoAction = createAsyncThunk< >( "organization/updateOrgInfoAction", async ( - { name, timezone, logo, isApprovalRequired }, + { name, privacyPolicyLink, timezone, logo, isApprovalRequired }, { rejectWithValue, getState, dispatch }, ) => { const { token } = getState().userAccount; @@ -57,6 +57,7 @@ export const updateOrgInfoAction = createAsyncThunk< try { const orgInfo = await patchOrgInfo(token, { name, + privacyPolicyLink, timezone, logo, isApprovalRequired, @@ -127,6 +128,7 @@ export const getStellarAccountAction = createAsyncThunk< const initialState: OrganizationInitialState = { data: { name: "", + privacyPolicyLink: "", logo: "", distributionAccountPublicKey: "", timezoneUtcOffset: "", @@ -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, diff --git a/src/types/index.ts b/src/types/index.ts index 1aead7e..12ddbfc 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -66,6 +66,7 @@ export type DisbursementDetailsInitialState = { export type OrganizationInitialState = { data: { name: string; + privacyPolicyLink: string; logo: string; distributionAccountPublicKey: string; timezoneUtcOffset: string; @@ -447,6 +448,7 @@ export type AccountProfile = { // ============================================================================= export type OrgUpdateInfo = { name?: string; + privacyPolicyLink?: string; timezone?: string; logo?: File; isApprovalRequired?: boolean; @@ -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;