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

Organisation language support #553

Merged
merged 5 commits into from
Oct 5, 2020
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
9 changes: 7 additions & 2 deletions src/containers/Automation/Automation.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ import React from 'react';
import { Automation } from './Automation';
import { MockedProvider } from '@apollo/client/testing';
import { render, wait, fireEvent } from '@testing-library/react';
import { getOrganizationQuery } from '../../mocks/Organization';
import { getOrganizationLanguagesQuery, getOrganizationQuery } from '../../mocks/Organization';
import { getAutomationQuery, filterAutomationQuery } from '../../mocks/Automation';

const mocks = [...getOrganizationQuery, getAutomationQuery, filterAutomationQuery];
const mocks = [
...getOrganizationQuery,
getAutomationQuery,
filterAutomationQuery,
getOrganizationLanguagesQuery,
];
const automation = (
<MockedProvider mocks={mocks} addTypename={false}>
<Automation match={{ params: { id: 1 } }} />
Expand Down
5 changes: 3 additions & 2 deletions src/containers/Collection/Collection.test.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { GET_GROUPS } from '../../graphql/queries/Group';
import { GET_TAGS } from '../../graphql/queries/Tag';
import { GET_LANGUAGES } from '../../graphql/queries/List';
import { GET_USERS } from '../../graphql/queries/User';
import { getOrganizationQuery } from '../../mocks/Organization';
import { getOrganizationLanguagesQuery, getOrganizationQuery } from '../../mocks/Organization';

export const listItemProps = {
deleteItemQuery: DELETE_COLLECTION,
Expand Down Expand Up @@ -243,5 +243,6 @@ export const LIST_ITEM_MOCKS = [
},
},
},
...getOrganizationQuery
...getOrganizationQuery,
getOrganizationLanguagesQuery,
];
5 changes: 3 additions & 2 deletions src/containers/Form/FormLayout.test.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GET_TAG, GET_TAGS, GET_TAGS_COUNT, FILTER_TAGS } from '../../graphql/qu
import { CREATE_TAG, DELETE_TAG, UPDATE_TAG } from '../../graphql/mutations/Tag';
import { Input } from '../../components/UI/Form/Input/Input';
import { getTagsQuery } from '../../mocks/Tag';
import { getOrganizationQuery } from '../../mocks/Organization';
import { getOrganizationLanguagesQuery, getOrganizationQuery } from '../../mocks/Organization';

export const listItemProps = {
deleteItemQuery: DELETE_TAG,
Expand Down Expand Up @@ -257,5 +257,6 @@ export const LIST_ITEM_MOCKS = [
},
},
getTagsQuery,
...getOrganizationQuery
...getOrganizationQuery,
getOrganizationLanguagesQuery,
];
19 changes: 10 additions & 9 deletions src/containers/Form/FormLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SEARCH_QUERY } from '../../graphql/queries/Search';
import { SEARCH_QUERY_VARIABLES } from '../../common/constants';
import { ToastMessage } from '../../components/UI/ToastMessage/ToastMessage';
import { NOTIFICATION } from '../../graphql/queries/Notification';
import { GET_ORGANIZATION } from '../../graphql/queries/Organization';
import { USER_LANGUAGES } from '../../graphql/queries/Organization';

export interface FormLayoutProps {
match: any;
Expand Down Expand Up @@ -110,13 +110,9 @@ export const FormLayout: React.SFC<FormLayoutProps> = ({
let toastMessage: {} | null | undefined;

// get the organization for current user and have languages option set to that.
const organization = useQuery(GET_ORGANIZATION, {
onCompleted: (data) => {
setLanguageId(data.organization.organization.activeLanguages[0].id);
client.writeQuery({
query: GET_ORGANIZATION,
data: data.organization,
});
const organization = useQuery(USER_LANGUAGES, {
onCompleted: (data: any) => {
setLanguageId(data.currentUser.user.organization.defaultLanguage.id);
},
});

Expand Down Expand Up @@ -158,6 +154,11 @@ export const FormLayout: React.SFC<FormLayoutProps> = ({
setErrorMessage(client, error);
return null;
},
refetchQueries: () => {
if (refetchQueries && refetchQueries.onUpdate) {
return [{ query: refetchQueries.onUpdate }];
} else return [];
},
});

const [createItem] = useMutation(createItemQuery, {
Expand Down Expand Up @@ -292,7 +293,7 @@ export const FormLayout: React.SFC<FormLayoutProps> = ({
};

let languageOptions = organization.data
? organization.data.organization.organization.activeLanguages.slice()
? organization.data.currentUser.user.organization.activeLanguages.slice()
: [];
// sort languages by their name
languageOptions.sort((first: any, second: any) => {
Expand Down
5 changes: 4 additions & 1 deletion src/containers/Group/Group.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import { MockedProvider } from '@apollo/client/testing';
import { Group } from './Group';
import { getGroupQuery, getGroupsQuery, getGroupUsersQuery } from '../../mocks/Group';
import { getUsersQuery } from '../../mocks/User';
import { getOrganizationQuery } from '../../mocks/Organization';
import { getOrganizationLanguagesQuery, getOrganizationQuery } from '../../mocks/Organization';

const mocks = [
getUsersQuery,
...getOrganizationQuery,
getGroupQuery,
getOrganizationLanguagesQuery,
getOrganizationLanguagesQuery,
getGroupQuery, // if you refetch then you need to include same mock twice
getGroupUsersQuery,
getGroupUsersQuery,
getGroupsQuery,
];

Expand Down
5 changes: 3 additions & 2 deletions src/containers/List/List.test.helper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GET_TAGS_COUNT, FILTER_TAGS, GET_TAGS } from '../../graphql/queries/Tag';
import { GET_LANGUAGES } from '../../graphql/queries/List';
import { DELETE_TAG } from '../../graphql/mutations/Tag';
import { getOrganizationQuery } from '../../mocks/Organization';
import { getOrganizationLanguagesQuery, getOrganizationQuery } from '../../mocks/Organization';

export const defaultProps = {
columnNames: ['label', 'description', 'keywords', 'actions'],
Expand Down Expand Up @@ -193,5 +193,6 @@ export const LIST_MOCKS = [
search,
searchCount,
getTags,
...getOrganizationQuery
...getOrganizationQuery,
getOrganizationLanguagesQuery,
];
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { GET_AUTOMATIONS } from '../../graphql/queries/Automation';
import { GET_LANGUAGES } from '../../graphql/queries/List';
import { getOrganizationQuery } from '../../mocks/Organization';
import { getOrganizationLanguagesQuery, getOrganizationQuery } from '../../mocks/Organization';

export const LIST_ITEM_MOCKS = [
{
request: {
query: GET_LANGUAGES,
variables: { opts: {order: 'ASC'} },
variables: { opts: { order: 'ASC' } },
},
result: {
data: {
Expand Down Expand Up @@ -65,5 +65,6 @@ export const LIST_ITEM_MOCKS = [
},
},
},
...getOrganizationQuery
...getOrganizationQuery,
getOrganizationLanguagesQuery,
];
5 changes: 3 additions & 2 deletions src/containers/OrganisationSettings/OrganisationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AutoComplete } from '../../components/UI/Form/AutoComplete/AutoComplete
import { Input } from '../../components/UI/Form/Input/Input';
import { FormLayout } from '../Form/FormLayout';
import { GET_AUTOMATIONS } from '../../graphql/queries/Automation';
import { GET_ORGANIZATION } from '../../graphql/queries/Organization';
import { GET_ORGANIZATION, USER_LANGUAGES } from '../../graphql/queries/Organization';
import {
CREATE_ORGANIZATION,
DELETE_ORGANIZATION,
Expand Down Expand Up @@ -111,7 +111,7 @@ export const OrganisationSettings: React.SFC<SettingsProps> = () => {

const { data } = useQuery(GET_AUTOMATIONS);
const { data: languages } = useQuery(GET_LANGUAGES, {
variables: { opts: {order: 'ASC'} },
variables: { opts: { order: 'ASC' } },
});
const [getOrg, { data: orgData }] = useLazyQuery<any>(GET_ORGANIZATION);

Expand Down Expand Up @@ -305,6 +305,7 @@ export const OrganisationSettings: React.SFC<SettingsProps> = () => {
listItemName="Settings"
dialogMessage={''}
formFields={formFields}
refetchQueries={{ onUpdate: USER_LANGUAGES }}
redirectionLink=""
cancelLink="chat"
linkParameter="id"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../../graphql/queries/User';
import { GET_LANGUAGES } from '../../graphql/queries/List';
import { GET_GROUPS } from '../../graphql/queries/Group';
import { getOrganizationQuery } from '../../mocks/Organization';
import { getOrganizationLanguagesQuery, getOrganizationQuery } from '../../mocks/Organization';

export const STAFF_MANAGEMENT_MOCKS = [
{
Expand Down Expand Up @@ -126,5 +126,6 @@ export const STAFF_MANAGEMENT_MOCKS = [
},
},
},
...getOrganizationQuery
...getOrganizationQuery,
getOrganizationLanguagesQuery,
];
3 changes: 2 additions & 1 deletion src/containers/Template/Template.test.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
GET_TEMPLATE,
} from '../../graphql/queries/Template';
import { DELETE_TEMPLATE, CREATE_TEMPLATE } from '../../graphql/mutations/Template';
import { getOrganizationQuery } from '../../mocks/Organization';
import { getOrganizationLanguagesQuery, getOrganizationQuery } from '../../mocks/Organization';

const count = {
request: {
Expand Down Expand Up @@ -293,4 +293,5 @@ export const TEMPLATE_MOCKS = [
filterByBody(''),
speedSendValidation,
...getOrganizationQuery,
getOrganizationLanguagesQuery,
];
21 changes: 19 additions & 2 deletions src/graphql/queries/Organization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ export const GET_ORGANIZATION = gql`
id
name
provider {
apiEndPoint
id
name
url
}
providerAppname
providerPhone
Expand All @@ -36,3 +34,22 @@ export const GET_ORGANIZATION = gql`
}
}
`;

export const USER_LANGUAGES = gql`
query currentUserOrganisationLanguages {
currentUser {
user {
organization {
activeLanguages {
id
label
}
defaultLanguage {
id
label
}
}
}
}
}
`;
2 changes: 2 additions & 0 deletions src/mocks/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { filterTagsQuery, getTagsQuery } from './Tag';
import { contactGroupsQuery } from './Contact';
import { CREATE_AND_SEND_MESSAGE_MUTATION, UPDATE_MESSAGE_TAGS } from '../graphql/mutations/Chat';
import { SEARCH_QUERY_VARIABLES as queryVariables } from '../common/constants';
import { getOrganizationLanguagesQuery } from './Organization';

const getConversationQuery = (data: any) => {
return {
Expand Down Expand Up @@ -220,6 +221,7 @@ export const CONVERSATION_MOCKS = [
addMessageTagSubscription,
deleteMessageTagSubscription,
savedSearchQuery,
getOrganizationLanguagesQuery,
conversationMessageQuery('2', 'Jane Doe', '919090909009'),
conversationMessageQuery('3', 'Jane Monroe', '919090709009'),
];
Expand Down
4 changes: 3 additions & 1 deletion src/mocks/Contact.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from '../graphql/queries/Contact';
import { getCurrentUserQuery } from './User';
import { filterTagsQuery } from './Tag';
import { getOrganizationQuery } from '../mocks/Organization';
import { getOrganizationLanguagesQuery, getOrganizationQuery } from '../mocks/Organization';
import { UPDATE_CONTACT } from '../graphql/mutations/Contact';

export const contactGroupsQuery = {
Expand Down Expand Up @@ -93,7 +93,9 @@ export const getContactDetailsQuery = {
export const LOGGED_IN_USER_MOCK = [
getCurrentUserQuery,
getContactDetailsQuery,
getOrganizationLanguagesQuery,
filterTagsQuery,
getCurrentUserQuery,
getContactQuery,
getContactDetailsQuery,
...getOrganizationQuery,
Expand Down
36 changes: 28 additions & 8 deletions src/mocks/Organization.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GET_ORGANIZATION } from '../graphql/queries/Organization';
import { GET_ORGANIZATION, USER_LANGUAGES } from '../graphql/queries/Organization';

export const getOrganizationQuery = [
{
Expand Down Expand Up @@ -33,10 +33,8 @@ export const getOrganizationQuery = [
startTime: '12:31:27',
},
provider: {
apiEndPoint: 'https://api.gupshup.io/sm/api/v1',
id: '1',
name: 'Gupshup',
url: 'https://gupshup.io/',
},
providerAppname: 'ADD_PROVIDER_API_KEY',
providerPhone: '917834811114',
Expand Down Expand Up @@ -79,10 +77,8 @@ export const getOrganizationQuery = [
startTime: '12:31:27',
},
provider: {
apiEndPoint: 'https://api.gupshup.io/sm/api/v1',
id: '1',
name: 'Gupshup',
url: 'https://gupshup.io/',
},
providerAppname: 'ADD_PROVIDER_API_KEY',
providerPhone: '917834811114',
Expand Down Expand Up @@ -125,10 +121,8 @@ export const getOrganizationQuery = [
startTime: '12:31:27',
},
provider: {
apiEndPoint: 'https://api.gupshup.io/sm/api/v1',
id: '1',
name: 'Gupshup',
url: 'https://gupshup.io/',
},
providerAppname: 'ADD_PROVIDER_API_KEY',
providerPhone: '917834811114',
Expand All @@ -137,5 +131,31 @@ export const getOrganizationQuery = [
},
},
},
}
},
];

export const getOrganizationLanguagesQuery = {
request: {
query: USER_LANGUAGES,
},
result: {
data: {
currentUser: {
user: {
organization: {
activeLanguages: [
{
id: '1',
label: 'English',
},
],
defaultLanguage: {
id: '1',
label: 'English',
},
},
},
},
},
},
};