Skip to content

Commit

Permalink
Fixed #1473: Unexpected behavior when updation of talawa admin member…
Browse files Browse the repository at this point in the history
…s profile. (#1499)

* fixed bug for incorrect updation of talawa admin members profile.

* added localstorage functionality for the root user

* fixes updation of applangcode functionality

* changed type id from String to ID

* changed type id from string to id, changed the schema to match the input to updateUserInput
  • Loading branch information
Devesh326 authored Jan 28, 2024
1 parent 8d34a8b commit 6a495ef
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
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 @@ -84,13 +84,21 @@ export const ADDRESS_DETAILS_FRAGMENT = 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

0 comments on commit 6a495ef

Please sign in to comment.