Fully implement SetUsername

This commit is contained in:
Chi Vinh Le
2018-01-09 12:25:44 +01:00
parent 2bcb324582
commit a2eb474a5c
4 changed files with 35 additions and 5 deletions
@@ -43,7 +43,7 @@ export const hideCreateUsernameDialog = () => ({
type: actions.HIDE_CREATEUSERNAME_DIALOG
});
export const updateUsername = ({username}) => ({
export const updateUsername = (username) => ({
type: actions.UPDATE_USERNAME,
username
});
@@ -198,6 +198,7 @@ export default function auth (state = initialState, action) {
user: {
...state.user,
username: action.username,
lowercaseUsername: action.username.toLowerCase(),
}
};
case actions.VERIFY_EMAIL_FAILURE:
@@ -230,7 +231,7 @@ export default function auth (state = initialState, action) {
case 'APOLLO_SUBSCRIPTION_RESULT':
// @TODO: These don't work anymore because apollo store has been decoupled
if (action.operationName === 'UserBanned' && state.user.id === action.variables.user_id) {
return {
...state,
@@ -234,6 +234,11 @@ export const withRejectUsername = withMutation(
})
});
const SetUsernameFragment = gql`
fragment Talk_SetUsername on User {
username
}`;
export const withChangeUsername = withMutation(
gql`
mutation ChangeUsername($id: ID!, $username: String!) {
@@ -249,6 +254,14 @@ export const withChangeUsername = withMutation(
id,
username,
},
update: (proxy) => {
const fragmentId = `User_${id}`;
const data = {
__typename: 'User',
username,
};
proxy.writeFragment({fragment: SetUsernameFragment, id: fragmentId, data});
}
});
}
})
@@ -269,6 +282,14 @@ export const withSetUsername = withMutation(
id,
username,
},
update: (proxy) => {
const fragmentId = `User_${id}`;
const data = {
__typename: 'User',
username,
};
proxy.writeFragment({fragment: SetUsernameFragment, id: fragmentId, data});
}
});
}
})