Skip to content

Commit 2666520

Browse files
authored
Merge pull request #1509 from CaliOpen/frontend/fix_compile
[frontend] fix ts error related to changes from develop branch
2 parents 2a48196 + 90fbea2 commit 2666520

File tree

12 files changed

+267
-167
lines changed

12 files changed

+267
-167
lines changed

src/frontend/web_application/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@
131131
"@types/lingui__react": "^2.8.3",
132132
"@types/lodash": "^4.14.168",
133133
"@types/openpgp": "^4.4.15",
134-
"@types/react": "^17.0.1",
135-
"@types/react-dom": "^17.0.0",
134+
"@types/react": "^17.0.3",
135+
"@types/react-dom": "^17.0.2",
136136
"@types/react-redux": "^7.1.16",
137137
"@types/react-router-dom": "^5.1.7",
138138
"@types/redux": "^3.6.0",
139-
"@typescript-eslint/eslint-plugin": "^4.15.0",
140-
"@typescript-eslint/parser": "^4.15.0",
139+
"@typescript-eslint/eslint-plugin": "^4.18.0",
140+
"@typescript-eslint/parser": "^4.18.0",
141141
"autoprefixer": "^9.7.6",
142142
"axios-mock-adapter": "^1.18.1",
143143
"babel-core": "^7.0.0-bridge.0",
@@ -193,10 +193,10 @@
193193
"stylelint-order": "^4.1.0",
194194
"stylelint-scss": "^3.19.0",
195195
"stylelint-webpack-plugin": "^2.1.1",
196-
"ts-loader": "^8.0.17",
197-
"typescript": "^4.1.5",
196+
"ts-loader": "^8.0.18",
197+
"typescript": "^4.2.3",
198198
"uglifyjs-webpack-plugin": "^2.2.0",
199-
"webpack": "^5.23.0",
199+
"webpack": "^5.26.2",
200200
"webpack-cli": "^4.5.0",
201201
"webpack-dev-server": "^3.11.2",
202202
"webpack-merge": "^5.7.3",
Lines changed: 114 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1+
import { PI, PrivacyFeature } from 'src/modules/pi/types';
2+
13
// Entity ---------------------------------------
2-
export interface ContactCommon {
3-
contact_id: string;
4-
title: string;
5-
family_name: string;
4+
interface NewPostalAddress {
5+
address_id?: string;
6+
city: string;
7+
country?: string;
8+
is_primary?: boolean;
9+
label?: string;
10+
postal_code?: string;
11+
region?: string;
12+
street?: string;
13+
type?: string;
614
}
715

8-
interface PrivacyIndex {
9-
technic: number;
10-
context: number;
11-
comportment: number;
16+
interface PostalAddress extends NewPostalAddress {
17+
address_id: string;
18+
city: string;
1219
}
1320

1421
interface Email {
@@ -19,32 +26,112 @@ interface Email {
1926
address: string;
2027
type: string;
2128
}
22-
export interface ContactPayload extends ContactCommon {
23-
// FIXME: types are not yet verified
24-
addresses: string[];
25-
privacy_features: {};
26-
phones: string[];
27-
date_insert: string;
28-
identities: string[];
29-
user_id?: string;
29+
30+
interface NewSocialIdentity {
31+
infos?: { [key: string]: any };
32+
name: string;
33+
type: string;
34+
}
35+
36+
interface SocialIdentity extends NewSocialIdentity {
37+
social_id: string;
38+
}
39+
40+
interface NewOrganization {
41+
department?: string;
42+
is_primary?: boolean;
43+
job_description?: string;
44+
label?: string;
45+
name: string;
46+
title?: string;
47+
type?: string;
48+
}
49+
50+
interface Organization extends NewOrganization {
51+
deleted?: boolean;
52+
organization_id: string;
53+
}
54+
55+
interface NewPhone {
56+
is_primary?: boolean;
57+
number: string;
58+
type?: string;
59+
uri?: string;
60+
}
61+
62+
interface Phone extends NewPhone {
63+
phone_id: string;
64+
normalized_number?: string;
65+
}
66+
67+
interface NewIM {
68+
address: string;
69+
is_primary?: boolean;
70+
label?: string;
71+
protocol?: string;
72+
type?: string;
73+
}
74+
75+
interface IM extends NewIM {
76+
im_id: string;
77+
}
78+
79+
interface NewPublicKey {
80+
key: string; //description : "DER or PEM key, base64 encoded"
81+
label: string;
82+
}
83+
84+
interface PublicKey extends NewPublicKey {
85+
alg?: string;
86+
crv?: string;
87+
date_insert?: string; //format: date-time
88+
date_update?: string; //format: date-time
89+
emails?: string[];
90+
expire_date?: string; //format: date-time
91+
fingerprint?: string;
92+
kty?: string;
93+
key_id: string;
94+
type?: string;
95+
resource_id: string;
96+
resource_type?: string;
97+
size?: number; //format: int32
98+
use?: string;
99+
user_id: string;
100+
x?: number; //format: int64
101+
y?: number; //format: int64
102+
}
103+
104+
export interface ContactCommon {
30105
additional_name?: string;
106+
addresses?: PostalAddress[];
107+
avatar?: string;
108+
contact_id: string;
109+
date_insert?: string;
31110
date_update?: string;
32-
organizations: string[];
33-
ims: string[];
34-
given_name: string;
35-
name_prefix?: string;
36-
deleted: number; // ?
37-
pi: PrivacyIndex;
38-
tags: string[];
111+
deleted?: string; // date-time
112+
emails?: Email[];
113+
family_name?: string;
114+
given_name?: string;
115+
groups?: string[];
116+
identities?: SocialIdentity[];
117+
ims?: IM[];
39118
infos?: {
119+
// object
40120
birthday?: string;
41121
};
42-
emails: Email[];
43-
family_name: string;
122+
name_prefix?: string;
44123
name_suffix?: string;
45-
avatar: string;
46-
public_keys: string[];
124+
organizations?: Organization[];
125+
phones?: Phone[];
126+
pi?: PI;
127+
privacy_features?: PrivacyFeature;
128+
public_keys?: PublicKey[];
129+
tags?: string[];
130+
title?: string;
131+
user_id: string;
47132
}
133+
134+
export interface ContactPayload extends ContactCommon {}
48135
// ---------------------------------------------
49136

50137
export type TSortDir = 'ASC' | 'DESC';
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface PI {
2+
technic: number;
3+
context: number;
4+
comportment: number;
5+
version: number;
6+
// [additional: string]: any, // XXX: not sure how to type `additionalProperties`
7+
}
8+
9+
export interface PrivacyFeature {
10+
[key: string]: any;
11+
}

src/frontend/web_application/src/modules/user/components/UserInfo/UserInfo.spec.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { render, screen, waitFor } from '@testing-library/react';
33
import { rest } from 'msw';
44
import { AllProviders } from 'test/providers';
55
import { server } from 'test/server';
6-
import { user } from 'test/msw-handlers/user';
6+
import { generateUser } from 'test/fixtures/user';
77
import { settings } from 'test/msw-handlers/settings';
88
import WithUser from '../WithUser';
99
import UserInfo from './index';
@@ -18,6 +18,7 @@ const Comp = () => (
1818
);
1919

2020
describe('component UserInfo', () => {
21+
const user = generateUser();
2122
beforeEach(() => {
2223
server.use(
2324
rest.get('/api/v1/me', (req, res, ctx) => {
@@ -37,6 +38,6 @@ describe('component UserInfo', () => {
3738
// TODO: rm (after using hooks)
3839
// Force re-render due to With<Thing> fetching
3940
await waitFor(() => screen.findByText('loading'));
40-
await waitFor(() => screen.findByText(user.name));
41+
await waitFor(() => screen.findByText(user.name || 'fail'));
4142
});
4243
});

src/frontend/web_application/src/modules/user/types.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import { PatchPayload } from 'src/types';
22
import { ContactCommon } from 'src/modules/contact/types';
3+
import { PI, PrivacyFeature } from 'src/modules/pi/types';
34

45
// Entity ---------------------------------------
56
export interface UserPayload {
6-
user_id: string;
77
contact: ContactCommon;
8+
date_insert?: string; // format: date-time
9+
family_name?: string;
10+
given_name?: string;
11+
name?: string;
12+
password?: string;
13+
params?: object;
14+
privacy_features?: PrivacyFeature;
15+
pi?: PI;
16+
user_id: string;
17+
recovery_email?: string;
818
}
919

1020
export type UserPatchPayload = PatchPayload<UserPayload>;

src/frontend/web_application/src/scenes/UserSecurity/components/OpenPGPGenerateForm.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,13 @@ function OpenPGPGenerateForm({ i18n, cancel, onSuccess }: Props) {
3939
const [isLoading, setIsLoading] = React.useState<boolean>(false);
4040
const [errors, setErrors] = React.useState<undefined | string[]>();
4141

42-
const user = useUser();
42+
const { user } = useUser();
4343

44-
const emailOptions = user?.contact.emails.map((email) => ({
45-
label: email.address,
46-
value: email.address,
47-
}));
44+
const emailOptions =
45+
user?.contact.emails?.map((email) => ({
46+
label: email.address,
47+
value: email.address,
48+
})) || [];
4849

4950
const errorsLabels = {};
5051

@@ -63,6 +64,9 @@ function OpenPGPGenerateForm({ i18n, cancel, onSuccess }: Props) {
6364

6465
const handleGenerateSubmit = async (event) => {
6566
event.preventDefault();
67+
if (!user) {
68+
return;
69+
}
6670
setIsLoading(true);
6771
const { passphrase, email } = generateValues;
6872
const manager = await getPGPManager();

src/frontend/web_application/src/scenes/UserSecurity/components/OpenPGPImportForm.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function OpenPGPImportForm({ i18n, cancel, onSuccess }: Props) {
6363
const [isLoading, setIsLoading] = React.useState<boolean>(false);
6464
const [errors, setErrors] = React.useState<Errors>({});
6565

66-
const user = useUser();
66+
const { user } = useUser();
6767

6868
const errorsLabels = {
6969
[ERROR_REQUIRED]: i18n._(
@@ -121,6 +121,10 @@ function OpenPGPImportForm({ i18n, cancel, onSuccess }: Props) {
121121

122122
const errors = validate(importValues);
123123

124+
if (!user) {
125+
return;
126+
}
127+
124128
if (errors) {
125129
setErrors(errors);
126130
return;

src/frontend/web_application/src/scenes/UserSecurity/components/OpenPGPPrivateKeys/index.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@ const FORM_TYPE_GENERATE = 'generate';
1919
const FORM_TYPE_IMPORT = 'import';
2020
type FormType = typeof FORM_TYPE_GENERATE | typeof FORM_TYPE_IMPORT;
2121

22+
// cf. getPrimaryKeysByFingerprint
23+
type KeysByFingerPrint = {
24+
[fingerprint: string]: {
25+
publicKeyArmored?: string;
26+
privateKeyArmored?: string;
27+
};
28+
};
29+
2230
function OpenPGPPrivateKeys() {
23-
const [keys, setKeys] = React.useState();
31+
const [keys, setKeys] = React.useState<KeysByFingerPrint>();
2432
const [editMode, setEditMode] = React.useState(false);
2533
const [formType, setFormType] = React.useState<FormType>(FORM_TYPE_GENERATE);
2634

@@ -61,8 +69,8 @@ function OpenPGPPrivateKeys() {
6169
<OpenPGPKey
6270
key={fingerprint}
6371
className="m-account-openpgp__keys"
64-
publicKeyArmored={key.publicKeyArmored}
65-
privateKeyArmored={key.privateKeyArmored}
72+
publicKeyArmored={key.publicKeyArmored || ''}
73+
privateKeyArmored={key.privateKeyArmored || ''}
6674
editMode={editMode}
6775
onDeleteKey={handleDeleteKey}
6876
/>

0 commit comments

Comments
 (0)