Skip to content

Commit 08d6c11

Browse files
authored
Merge pull request PapillonApp#402 from PapillonApp/account/identity
feat(account): Ajout des informations d'identité
2 parents 3d644df + 92883c6 commit 08d6c11

File tree

3 files changed

+150
-12
lines changed

3 files changed

+150
-12
lines changed

src/stores/account/types.ts

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ export interface Personalization {
6565
}
6666
}
6767

68+
export interface Identity {
69+
firstName?: string,
70+
lastName?: string,
71+
civility?: string,
72+
boursier?: boolean,
73+
ine?: string,
74+
birthDate?: Date,
75+
birthPlace?: string,
76+
phone?: string[],
77+
email?: string[],
78+
address?: {
79+
street?: string,
80+
zipCode?: string,
81+
city?: string,
82+
},
83+
}
84+
6885
export interface CurrentAccountStore {
6986
/** Si un compte est en cours d'utilisation, on obtient l'ID, sinon `null`. */
7087
account: PrimaryAccount | null
@@ -96,19 +113,20 @@ export enum AccountService {
96113
* for EVERY accounts stored.
97114
*/
98115
interface BaseAccount {
99-
localID: string
100-
isExternal: false
116+
localID: string;
117+
isExternal: false;
101118

102-
name: string
103-
className?: string
104-
schoolName?: string
105-
linkedExternalLocalIDs: string[]
119+
name: string;
120+
className?: string;
121+
schoolName?: string;
122+
linkedExternalLocalIDs: string[];
123+
identity: Partial<Identity>;
106124

107125
studentName: {
108-
first: string
109-
last: string
110-
},
111-
personalization: Partial<Personalization>
126+
first: string;
127+
last: string;
128+
};
129+
personalization: Partial<Personalization>;
112130
}
113131

114132
interface BaseExternalAccount {

src/views/login/IdentityProvider/actions/BackgroundIUTLannion.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,39 @@ import { WebView } from "react-native-webview";
1111
import type { Screen } from "@/router/helpers/types";
1212
import { FadeInDown, FadeOutUp } from "react-native-reanimated";
1313
import { animPapillon } from "@/utils/ui/animations";
14+
import { da } from "date-fns/locale";
1415

1516
const capitalizeFirst = (str: string) => {
1617
str = str.toLowerCase();
1718
return str.charAt(0).toUpperCase() + str.slice(1);
1819
};
1920

21+
const buildIdentity = (data: any) => {
22+
return {
23+
firstName: capitalizeFirst(data["relevé"].etudiant.prenom || ""),
24+
lastName: (data["relevé"].etudiant.nom || "").toUpperCase(),
25+
civility: data["relevé"].etudiant.civilite || undefined,
26+
boursier: data["relevé"].etudiant.boursier || false,
27+
ine: data["relevé"].etudiant.code_ine || undefined,
28+
birthDate: data["relevé"].etudiant.date_naissance ? (
29+
new Date(data["relevé"].etudiant.date_naissance.split("/").reverse().join("-")).getTime()
30+
) : undefined,
31+
birthPlace: data["relevé"].etudiant.lieu_naissance || undefined,
32+
phone: [
33+
data["relevé"].etudiant.telephonemobile ? (data["relevé"].etudiant.telephonemobile).replaceAll(".", " ") : undefined,
34+
],
35+
email: [
36+
data["relevé"].etudiant.email || undefined,
37+
data["relevé"].etudiant.emailperso || undefined,
38+
],
39+
address: {
40+
street: data["relevé"].etudiant.domicile || undefined,
41+
city: data["relevé"].etudiant.villedomicile || undefined,
42+
zipCode: data["relevé"].etudiant.codepostaldomicile || undefined,
43+
},
44+
};
45+
};
46+
2047
const BackgroundIUTLannion: Screen<"BackgroundIUTLannion"> = ({ route, navigation }) => {
2148
const params = route.params;
2249
let username = params?.username || null;
@@ -55,6 +82,8 @@ const BackgroundIUTLannion: Screen<"BackgroundIUTLannion"> = ({ route, navigatio
5582
rawData: data,
5683
});
5784

85+
mutateProperty("identity", buildIdentity(data));
86+
5887
navigation.goBack();
5988
}
6089
};
@@ -70,6 +99,8 @@ const BackgroundIUTLannion: Screen<"BackgroundIUTLannion"> = ({ route, navigatio
7099
rawData: data,
71100
},
72101

102+
identity: buildIdentity(data),
103+
73104
credentials: {
74105
username: username || "",
75106
password: password || ""

src/views/settings/SettingsProfile.tsx

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import { Screen } from "@/router/helpers/types";
33
import { useCurrentAccount } from "@/stores/account";
44
import { useTheme } from "@react-navigation/native";
55
import * as ImagePicker from "expo-image-picker";
6-
import { Camera, Plus, TextCursorInput, User2, UserCircle2, WholeWord } from "lucide-react-native";
6+
import { Camera, ChevronDown, ChevronUp, Plus, TextCursorInput, User2, UserCircle2, WholeWord } from "lucide-react-native";
77
import React, { useEffect, useRef, useState } from "react";
8-
import { ActivityIndicator, Image, KeyboardAvoidingView, ScrollView, Switch, TextInput } from "react-native";
8+
import { ActivityIndicator, Alert, Image, KeyboardAvoidingView, ScrollView, Switch, TextInput } from "react-native";
99
import { useSafeAreaInsets } from "react-native-safe-area-context";
1010

11+
import * as Clipboard from "expo-clipboard";
12+
import { TouchableOpacity } from "react-native-gesture-handler";
13+
1114
const SettingsProfile: Screen<"SettingsProfile"> = ({ navigation }) => {
1215
const theme = useTheme();
1316
const insets = useSafeAreaInsets();
@@ -80,6 +83,48 @@ const SettingsProfile: Screen<"SettingsProfile"> = ({ navigation }) => {
8083
});
8184
}, [hideNameOnHomeScreen, hideProfilePicOnHomeScreen]);
8285

86+
const identityData = account.identity ? [
87+
account.identity.civility && {
88+
label: "Civilité",
89+
value: account.identity.civility === "M" ? "Monsieur" : "Madame",
90+
},
91+
account.identity.birthDate && {
92+
label: "Date de naissance",
93+
value: new Date(account.identity.birthDate).toLocaleDateString("fr-FR", {
94+
year: "numeric",
95+
month: "long",
96+
day: "numeric",
97+
}),
98+
},
99+
account.identity.birthPlace && {
100+
label: "Lieu de naissance",
101+
value: account.identity.birthPlace,
102+
},
103+
account.identity.ine && {
104+
label: "INE",
105+
value: account.identity.ine,
106+
},
107+
account.identity.boursier && {
108+
label: "Boursier",
109+
value: "Oui",
110+
},
111+
account.identity.email && {
112+
label: "Email",
113+
value: account.identity.email[0],
114+
},
115+
account.identity.phone && {
116+
label: "Téléphone",
117+
value: account.identity.phone[0],
118+
},
119+
account.identity.address && {
120+
label: "Adresse",
121+
value: `${account.identity.address.street}, ${account.identity.address.zipCode} ${account.identity.address.city}`,
122+
},
123+
].filter(Boolean) as { label: string, value: string }[
124+
] : [];
125+
126+
const [showIdentity, setShowIdentity] = useState(false);
127+
83128
return (
84129
<KeyboardAvoidingView
85130
behavior="padding"
@@ -228,6 +273,50 @@ const SettingsProfile: Screen<"SettingsProfile"> = ({ navigation }) => {
228273
</NativeText>
229274
</NativeItem>
230275
</NativeList>
276+
277+
{account.identity && Object.keys(account.identity) !== undefined && Object.keys(account.identity).length > 0 && (
278+
<NativeListHeader
279+
label="Informations d'identité"
280+
trailing={
281+
<TouchableOpacity
282+
onPress={() => setShowIdentity(!showIdentity)}
283+
>
284+
{showIdentity ?
285+
<ChevronUp
286+
size={24}
287+
color={theme.colors.primary}
288+
/> :
289+
<ChevronDown
290+
size={24}
291+
color={theme.colors.primary}
292+
/>
293+
}
294+
</TouchableOpacity>
295+
}
296+
/>
297+
)}
298+
299+
{showIdentity && (
300+
<NativeList>
301+
{identityData.map((item, index) => (
302+
<NativeItem
303+
key={"identityData_"+index}
304+
onPress={async () => {
305+
await Clipboard.setStringAsync(item.value);
306+
Alert.alert("Copié", "L'information a été copiée dans le presse-papier.");
307+
}}
308+
chevron={false}
309+
>
310+
<NativeText variant="subtitle">
311+
{item.label}
312+
</NativeText>
313+
<NativeText variant="body">
314+
{item.value}
315+
</NativeText>
316+
</NativeItem>
317+
))}
318+
</NativeList>
319+
)}
231320
</ScrollView>
232321
</KeyboardAvoidingView>
233322
);

0 commit comments

Comments
 (0)