Skip to content

Commit 4e51097

Browse files
committed
More typings updates
1 parent 796f54f commit 4e51097

File tree

8 files changed

+510
-573
lines changed

8 files changed

+510
-573
lines changed

apps/client/src/core/auth/google/google.tsx

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import * as mainSelectors from '~store/main/main.selectors';
99
import { addToast } from '@generatedata/utils/general';
1010
import langUtils from '@generatedata/utils/lang';
1111
import clientConfig from '@generatedata/config/clientConfig';
12+
import { LOGIN_WITH_GOOGLE } from '../../mutations';
1213

1314
const googleBtnId = 'google-signin-button';
1415

@@ -41,52 +42,32 @@ const onAuthenticated = async (googleUser: any, opts: AuthenticatedOptions = {})
4142
store.dispatch(setOnloadAuthDetermined());
4243
} else {
4344
const googleToken = googleUser.credential;
44-
const response = await apolloClient.mutate({
45-
mutation: gql`
46-
mutation LoginWithGoogle($googleToken: String!) {
47-
loginWithGoogle(googleToken: $googleToken) {
48-
token
49-
refreshToken
50-
tokenExpiry
51-
success
52-
error
53-
firstName
54-
lastName
55-
expiryDate
56-
accountType
57-
dateCreated
58-
email
59-
numRowsGenerated
60-
profileImage
61-
country
62-
region
63-
}
64-
}
65-
`,
45+
const { data } = await apolloClient.mutate({
46+
mutation: LOGIN_WITH_GOOGLE,
6647
variables: { googleToken }
6748
});
6849

69-
if (response.data.loginWithGoogle.success) {
70-
const { tokenExpiry, refreshToken } = response.data.loginWithGoogle;
50+
if (data?.loginWithGoogle?.success) {
51+
const { tokenExpiry, refreshToken } = data.loginWithGoogle;
7152

7253
store.dispatch(
7354
setAuthenticationData({
74-
...response.data.loginWithGoogle,
55+
...data.loginWithGoogle,
7556
authMethod: AuthMethod.google
7657
})
7758
);
7859

79-
Cookies.set('refreshToken', refreshToken, {
80-
expires: new Date(tokenExpiry)
60+
Cookies.set('refreshToken', refreshToken!, {
61+
expires: new Date(tokenExpiry!)
8162
});
82-
onLoginSuccess(tokenExpiry, options.onPageRender, store.dispatch);
63+
onLoginSuccess(tokenExpiry!, options.onPageRender, store.dispatch);
8364
} else {
84-
if (response.data.loginWithGoogle.error === 'accountExpired') {
65+
if (data?.loginWithGoogle?.error === 'accountExpired') {
8566
addToast({
8667
type: 'error',
8768
message: i18n.core.accountExpiredMsg
8869
});
89-
} else if (response.data.loginWithGoogle.error === 'noUserAccount') {
70+
} else if (data?.loginWithGoogle?.error === 'noUserAccount') {
9071
addToast({
9172
type: 'error',
9273
message: i18n.core.userAccountNotFound

apps/client/src/core/mutations.ts

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,168 @@ export const UPDATE_DATA_SET_GENERATION_COUNT: TypedDocumentNode<Mutation> = gql
3838
}
3939
}
4040
`;
41+
42+
export const LOGIN_MUTATION: TypedDocumentNode<Mutation> = gql`
43+
mutation LoginMutation($email: String!, $password: String!) {
44+
login(email: $email, password: $password) {
45+
token
46+
tokenExpiry
47+
error
48+
refreshToken
49+
success
50+
accountId
51+
firstName
52+
lastName
53+
email
54+
country
55+
region
56+
expiryDate
57+
accountType
58+
accountStatus
59+
dateCreated
60+
numRowsGenerated
61+
profileImage
62+
wasOneTimeLogin
63+
}
64+
}
65+
`;
66+
67+
export const LOGIN_WITH_GOOGLE: TypedDocumentNode<Mutation> = gql`
68+
mutation LoginWithGoogle($googleToken: String!) {
69+
loginWithGoogle(googleToken: $googleToken) {
70+
token
71+
refreshToken
72+
tokenExpiry
73+
success
74+
error
75+
firstName
76+
lastName
77+
expiryDate
78+
accountType
79+
dateCreated
80+
email
81+
numRowsGenerated
82+
profileImage
83+
country
84+
region
85+
}
86+
}
87+
`;
88+
89+
export const CREATE_USER_ACCOUNT: TypedDocumentNode<Mutation> = gql`
90+
mutation CreateUserAccount(
91+
$firstName: String!
92+
$lastName: String!
93+
$email: String!
94+
$country: String
95+
$region: String
96+
$accountStatus: AccountStatus
97+
$expiryDate: String
98+
$oneTimePassword: String
99+
) {
100+
createUserAccount(
101+
firstName: $firstName
102+
lastName: $lastName
103+
email: $email
104+
country: $country
105+
region: $region
106+
accountStatus: $accountStatus
107+
expiryDate: $expiryDate
108+
oneTimePassword: $oneTimePassword
109+
) {
110+
success
111+
}
112+
}
113+
`;
114+
115+
export const DELETE_DATA_SET: TypedDocumentNode<Mutation> = gql`
116+
mutation DeleteDataSet($dataSetId: ID!) {
117+
deleteDataSet(dataSetId: $dataSetId) {
118+
success
119+
error
120+
}
121+
}
122+
`;
123+
124+
export const SAVE_NEW_DATA_SET: TypedDocumentNode<Mutation> = gql`
125+
mutation SaveNewDataSet($dataSetName: String!, $content: String!) {
126+
saveNewDataSet(dataSetName: $dataSetName, content: $content) {
127+
success
128+
error
129+
dataSetId
130+
savedDate
131+
}
132+
}
133+
`;
134+
135+
export const RENAME_DATA_SET: TypedDocumentNode<Mutation> = gql`
136+
mutation RenameDataSet($dataSetId: ID!, $dataSetName: String!) {
137+
renameDataSet(dataSetId: $dataSetId, dataSetName: $dataSetName) {
138+
success
139+
error
140+
}
141+
}
142+
`;
143+
144+
export const SAVE_CURRENT_DATA_SET: TypedDocumentNode<Mutation> = gql`
145+
mutation SaveDataSet($dataSetId: ID!, $content: String!) {
146+
saveDataSet(dataSetId: $dataSetId, content: $content) {
147+
success
148+
error
149+
dataSetId
150+
savedDate
151+
}
152+
}
153+
`;
154+
155+
export const SAVE_CURRENT_ACCOUNT: TypedDocumentNode<Mutation> = gql`
156+
mutation UpdateCurrentAccount($firstName: String!, $lastName: String!, $email: String!, $country: String!, $region: String) {
157+
updateCurrentAccount(firstName: $firstName, lastName: $lastName, email: $email, country: $country, region: $region) {
158+
success
159+
}
160+
}
161+
`;
162+
163+
export const SAVE_ACCOUNT: TypedDocumentNode<Mutation> = gql`
164+
mutation UpdateAccount(
165+
$accountId: ID!
166+
$accountStatus: AccountStatus
167+
$firstName: String!
168+
$lastName: String!
169+
$email: String!
170+
$country: String!
171+
$region: String
172+
$expiryDate: String
173+
) {
174+
updateAccount(
175+
accountId: $accountId
176+
accountStatus: $accountStatus
177+
firstName: $firstName
178+
lastName: $lastName
179+
email: $email
180+
country: $country
181+
region: $region
182+
expiryDate: $expiryDate
183+
) {
184+
success
185+
}
186+
}
187+
`;
188+
189+
export const UPDATE_PASSWORD: TypedDocumentNode<Mutation> = gql`
190+
mutation UpdatePassword($currentPassword: String!, $newPassword: String!) {
191+
updatePassword(currentPassword: $currentPassword, newPassword: $newPassword) {
192+
success
193+
error
194+
}
195+
}
196+
`;
197+
198+
export const DELETE_ACCOUNT: TypedDocumentNode<Mutation> = gql`
199+
mutation DeleteAccount($accountId: ID!) {
200+
deleteAccount(accountId: $accountId) {
201+
success
202+
error
203+
}
204+
}
205+
`;

0 commit comments

Comments
 (0)