Skip to content

Commit e7c096c

Browse files
committed
Refactor useIdentityStates to improve readability and maintainability
1 parent 844c901 commit e7c096c

File tree

1 file changed

+41
-42
lines changed

1 file changed

+41
-42
lines changed
Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
type useIdentityStateReturnType = {
2-
getStateColor: (state: number) => string;
3-
getStateName: (state: number) => string;
4-
getStateInfos: (state: number) => { color: string, name: string, value: number };
2+
getStateColor: (state: number) => string;
3+
getStateName: (state: number) => string;
4+
getStateInfos: (state: number) => { color: string, name: string, value: number };
55
};
66

77
export enum IdentityState {
@@ -16,46 +16,45 @@ export enum IdentityState {
1616
}
1717

1818
export const IdentityStateList = [
19-
{ value: IdentityState.SYNCED, text: 'Synchronisée', color: 'info', icon: 'mdi-circle', display: true},
20-
{ value: IdentityState.TO_SYNC, text: 'A Synchroniser', color: 'info', icon: 'mdi-circle', display: true },
21-
{ value: IdentityState.TO_VALIDATE, text: 'A valider', color: 'positive', icon: 'mdi-circle', display: true },
22-
{ value: IdentityState.UNKNOWN, text: 'Inconnu', color: 'grey', icon: 'mdi-circle', display: true},
23-
{ value: IdentityState.TO_CREATE, text: 'A créer', color: 'grey', icon: 'mdi-circle', display: false},
24-
{ value: IdentityState.TO_COMPLETE, text: 'A compléter', color: 'warning', icon: 'mdi-circle', display: true },
25-
{ value: IdentityState.ON_ERROR, text: 'En erreur', color: 'negative', icon: 'mdi-circle', display: true },
26-
{ value: IdentityState.PROCESSING, text: 'En cours de synchronisation', color: 'warning', icon: 'mdi-loading', display: true },
19+
{ value: IdentityState.SYNCED, text: 'Synchronisée', color: 'positive', icon: 'mdi-circle', display: true },
20+
{ value: IdentityState.TO_SYNC, text: 'A Synchroniser', color: 'ambre', icon: 'mdi-circle', display: true },
21+
{ value: IdentityState.TO_VALIDATE, text: 'A valider', color: 'info', icon: 'mdi-circle', display: true },
22+
{ value: IdentityState.UNKNOWN, text: 'Inconnu', color: 'grey', icon: 'mdi-circle', display: true },
23+
{ value: IdentityState.TO_CREATE, text: 'A créer', color: 'grey', icon: 'mdi-circle', display: false },
24+
{ value: IdentityState.TO_COMPLETE, text: 'A compléter', color: 'warning', icon: 'mdi-circle', display: true },
25+
{ value: IdentityState.ON_ERROR, text: 'En erreur', color: 'negative', icon: 'mdi-circle', display: true },
26+
{ value: IdentityState.PROCESSING, text: 'En cours de synchronisation', color: 'warning', icon: 'mdi-loading', display: true },
2727
];
2828

29-
export function useIdentityStates(): useIdentityStateReturnType
30-
{
31-
function getStateColor(state: number): string {
32-
const found = IdentityStateList.find(item => item.value === state);
33-
if (found && found?.display) return found.color;
34-
return 'grey';
35-
}
36-
37-
function getStateName(state: number): string {
38-
const found = IdentityStateList.find(item => item.value === state);
39-
if (found && found?.display) return found.text;
40-
return 'Inconnu';
41-
}
42-
43-
function getStateIcon(state: number): string {
44-
const found = IdentityStateList.find(item => item.value === state);
45-
if (found && found?.display) return found.icon;
46-
return 'mdi-circle';
47-
}
48-
49-
function getStateInfos(state: number): { color: string, name: string, icon: string, value: number }{
50-
const found = IdentityStateList.find(item => item.value === state);
51-
return {
52-
color: found ? found.color : 'grey',
53-
name: found ? found.text : 'Unknown',
54-
icon: found ? found.icon : 'mdi-circle',
55-
value: state
56-
};
57-
}
58-
59-
return { getStateColor, getStateName, getStateInfos};
29+
export function useIdentityStates(): useIdentityStateReturnType {
30+
function getStateColor(state: number): string {
31+
const found = IdentityStateList.find(item => item.value === state);
32+
if (found && found?.display) return found.color;
33+
return 'grey';
34+
}
35+
36+
function getStateName(state: number): string {
37+
const found = IdentityStateList.find(item => item.value === state);
38+
if (found && found?.display) return found.text;
39+
return 'Inconnu';
40+
}
41+
42+
function getStateIcon(state: number): string {
43+
const found = IdentityStateList.find(item => item.value === state);
44+
if (found && found?.display) return found.icon;
45+
return 'mdi-circle';
46+
}
47+
48+
function getStateInfos(state: number): { color: string, name: string, icon: string, value: number } {
49+
const found = IdentityStateList.find(item => item.value === state);
50+
return {
51+
color: found ? found.color : 'grey',
52+
name: found ? found.text : 'Unknown',
53+
icon: found ? found.icon : 'mdi-circle',
54+
value: state
55+
};
56+
}
57+
58+
return { getStateColor, getStateName, getStateInfos };
6059
}
6160

0 commit comments

Comments
 (0)