Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #1473: Unexpected behavior when updation of talawa admin members profile. #1499

Merged
Merged
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
2 changes: 2 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -900,9 +900,11 @@ input UpdateOrganizationInput {
}

input UpdateUserInput {
id: ID
email: EmailAddress
firstName: String
lastName: String
applangcode: String
}

input UpdateUserPasswordInput {
Expand Down
10 changes: 9 additions & 1 deletion src/GraphQl/Mutations/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,21 @@ export const UPDATE_ORGANIZATION_MUTATION = gql`

export const UPDATE_USER_MUTATION = gql`
mutation UpdateUserProfile(
$id: ID
$firstName: String
$lastName: String
$email: EmailAddress
$applangcode: String
$file: String
) {
updateUserProfile(
data: { firstName: $firstName, lastName: $lastName, email: $email }
data: {
firstName: $firstName
lastName: $lastName
email: $email
id: $id
applangcode: $applangcode
}
file: $file
) {
_id
Expand Down
18 changes: 14 additions & 4 deletions src/components/UserUpdate/UserUpdate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import { toast } from 'react-toastify';
import { errorHandler } from 'utils/errorHandler';
import { Form } from 'react-bootstrap';
import Loader from 'components/Loader/Loader';
// import useLocalStorage from 'utils/useLocalStorage';

// const { getItem, setItem } = useLocalStorage();

interface InterfaceUserUpdateProps {
id: string;
Expand Down Expand Up @@ -54,6 +57,7 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
firstName: data?.user?.firstName,
lastName: data?.user?.lastName,
email: data?.user?.email,
applangcode: data?.user?.applangcode,
});
}
}, [data]);
Expand All @@ -72,6 +76,7 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
const firstName = formState.firstName;
const lastName = formState.lastName;
const email = formState.email;
const applangcode = formState.applangcode;
const file = formState.file;
let toSubmit = true;
if (firstName.trim().length == 0 || !firstName) {
Expand All @@ -90,9 +95,11 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
const { data } = await updateUser({
variables: {
//Currently on these fields are supported by the api
id: currentUrl,
firstName,
lastName,
email,
applangcode,
file,
},
});
Expand All @@ -106,10 +113,13 @@ const UserUpdate: React.FC<InterfaceUserUpdateProps> = ({
applangcode: '',
file: '',
});
localStorage.setItem('FirstName', firstName);
localStorage.setItem('LastName', lastName);
localStorage.setItem('Email', email);
localStorage.setItem('UserImage', file);

if (localStorage.getItem('id') === currentUrl) {
localStorage.setItem('FirstName', firstName);
localStorage.setItem('LastName', lastName);
localStorage.setItem('Email', email);
localStorage.setItem('UserImage', file);
}
toast.success('Successful updated');

toggleStateValue();
Expand Down
Loading