Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
16 changes: 13 additions & 3 deletions packages/client-graphql/src/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,13 @@ export const getDraftPreferencePage =

const UPDATE_RECIPIENT_PREFERENCES = `
mutation UpdateRecipientPreferences($id: String!, $preferences: PreferencesInput!, $accountId: String) {
updatePreferences(templateId: $id preferences: $preferences accountId: $accountId)
updatePreferences(templateId: $id preferences: $preferences accountId: $accountId) {
templateId
status
hasCustomRouting
routingPreferences
digestSchedule
}
}
`;

Expand All @@ -168,7 +174,7 @@ export const updateRecipientPreferences =
return Promise.resolve();
}

await client
const results = await client
.mutation(UPDATE_RECIPIENT_PREFERENCES, {
id: payload.templateId,
preferences: {
Expand All @@ -181,7 +187,11 @@ export const updateRecipientPreferences =
})
.toPromise();

return payload;
if (results.error) {
throw results.error;
}

return results.data?.updatePreferences ?? payload;
};

export default (
Expand Down
9 changes: 9 additions & 0 deletions packages/react-hooks/src/preferences/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default (state: PreferenceState = initialState, action) => {
return {
...state,
isUpdating: false,
error: undefined,
recipientPreferences: state.recipientPreferences?.map((preference) => {
if (preference.templateId === action?.payload?.templateId) {
return action?.payload;
Expand All @@ -64,6 +65,14 @@ export default (state: PreferenceState = initialState, action) => {
}),
};
}

case "preferences/UPDATE_RECIPIENT_PREFERENCES/ERROR": {
return {
...state,
isUpdating: false,
error: action?.ex,
};
}
}

return state;
Expand Down
1 change: 1 addition & 0 deletions packages/react-hooks/src/preferences/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export type PreferenceSection = {
};

export interface PreferenceState {
error?: Error;
isLoading?: boolean;
isUpdating?: boolean;
preferences?: IPreferenceTemplate[];
Expand Down
Loading