-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Made code reviews and added birth date field
- Loading branch information
1 parent
8a47741
commit 21c2969
Showing
3 changed files
with
119 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,92 @@ | ||
import type { CodeDescrType } from '@/dto/CommonTypesDto' | ||
import type { CodeDescrType } from "@/dto/CommonTypesDto"; | ||
|
||
export interface Address { | ||
locationName: string | ||
streetAddress: string | ||
country: CodeDescrType | ||
province: CodeDescrType | ||
city: string | ||
postalCode: string | ||
locationName: string; | ||
streetAddress: string; | ||
country: CodeDescrType; | ||
province: CodeDescrType; | ||
city: string; | ||
postalCode: string; | ||
} | ||
|
||
export interface Contact { | ||
locationNames: CodeDescrType[] | ||
contactType: CodeDescrType | ||
firstName: string | ||
lastName: string | ||
phoneNumber: string | ||
email: string | ||
locationNames: CodeDescrType[]; | ||
contactType: CodeDescrType; | ||
firstName: string; | ||
lastName: string; | ||
phoneNumber: string; | ||
email: string; | ||
} | ||
|
||
export interface FormDataDto { | ||
businessInformation: { | ||
businessType: string | ||
legalType: string | ||
clientType: string | ||
incorporationNumber: string | ||
businessName: string | ||
goodStandingInd: string | ||
} | ||
businessType: string; | ||
legalType: string; | ||
clientType: string; | ||
incorporationNumber: string; | ||
businessName: string; | ||
goodStandingInd: string; | ||
birthDate: string; | ||
}; | ||
location: { | ||
addresses: Address[] | ||
contacts: Contact[] | ||
} | ||
addresses: Address[]; | ||
contacts: Contact[]; | ||
}; | ||
} | ||
|
||
export interface ForestClientDetailsDto { | ||
name: string | ||
id: string | ||
goodStanding: boolean | ||
addresses: Address[] | ||
contacts: Contact[] | ||
name: string; | ||
id: string; | ||
goodStanding: boolean; | ||
addresses: Address[]; | ||
contacts: Contact[]; | ||
} | ||
|
||
export const formDataDto: FormDataDto = { | ||
businessInformation: { | ||
businessType: '', | ||
legalType: '', | ||
clientType: '', | ||
incorporationNumber: '', | ||
businessName: '', | ||
goodStandingInd: '', | ||
businessType: "", | ||
legalType: "", | ||
clientType: "", | ||
incorporationNumber: "", | ||
businessName: "", | ||
goodStandingInd: "", | ||
birthDate: "", | ||
}, | ||
location: { | ||
addresses: [ | ||
{ | ||
locationName: 'Mailing address', | ||
streetAddress: '', | ||
country: { value: 'CA', text: 'Canada' }, | ||
province: { value: 'BC', text: 'British Columbia' }, | ||
city: '', | ||
postalCode: '', | ||
locationName: "Mailing address", | ||
streetAddress: "", | ||
country: { value: "CA", text: "Canada" }, | ||
province: { value: "BC", text: "British Columbia" }, | ||
city: "", | ||
postalCode: "", | ||
}, | ||
], | ||
contacts: [], | ||
}, | ||
} | ||
}; | ||
|
||
export const emptyAddress = (): Address => | ||
JSON.parse( | ||
JSON.stringify({ | ||
locationName: '', | ||
streetAddress: '', | ||
country: { value: 'CA', text: 'Canada' }, | ||
province: { value: 'BC', text: 'British Columbia' }, | ||
city: '', | ||
postalCode: '', | ||
}), | ||
) | ||
locationName: "", | ||
streetAddress: "", | ||
country: { value: "CA", text: "Canada" }, | ||
province: { value: "BC", text: "British Columbia" }, | ||
city: "", | ||
postalCode: "", | ||
}) | ||
); | ||
|
||
export const emptyContact: Contact = { | ||
locationNames: [], | ||
contactType: { value: '', text: '' }, | ||
firstName: '', | ||
lastName: '', | ||
phoneNumber: '', | ||
email: '', | ||
} | ||
contactType: { value: "", text: "" }, | ||
firstName: "", | ||
lastName: "", | ||
phoneNumber: "", | ||
email: "", | ||
}; | ||
|
||
export const newFormDataDto = (): FormDataDto => JSON.parse(JSON.stringify(formDataDto)) | ||
export const newFormDataDto = (): FormDataDto => | ||
JSON.parse(JSON.stringify(formDataDto)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,110 @@ | ||
import type { SessionProperties, Submitter } from '@/dto/CommonTypesDto' | ||
import { backendUrl } from '@/CoreConstants' | ||
import type { SessionProperties, Submitter } from "@/dto/CommonTypesDto"; | ||
import { backendUrl } from "@/CoreConstants"; | ||
|
||
class ForestClientUserSession implements SessionProperties { | ||
public user: Submitter | undefined | ||
public user: Submitter | undefined; | ||
|
||
public constructor () { | ||
this.loadUser() | ||
public constructor() { | ||
this.loadUser(); | ||
} | ||
|
||
logIn = (provider: string): void => { | ||
window.location.href = `${backendUrl}/login?code=${provider}` | ||
} | ||
window.location.href = `${backendUrl}/login?code=${provider}`; | ||
}; | ||
|
||
logOut = (): void => { | ||
this.user = undefined | ||
window.location.href = `${backendUrl}/logout` | ||
} | ||
this.user = undefined; | ||
window.location.href = `${backendUrl}/logout`; | ||
}; | ||
|
||
isLoggedIn = (): boolean => { | ||
return this.loadDetails() !== undefined | ||
} | ||
return this.loadDetails() !== undefined; | ||
}; | ||
|
||
loadDetails = (): Submitter | undefined => { | ||
if (this.user === undefined) { | ||
this.loadUser() | ||
this.loadUser(); | ||
} | ||
return this.user | ||
} | ||
return this.user; | ||
}; | ||
|
||
private processName = ( | ||
payload: any, | ||
provider: string | ||
): { firstName: string; lastName: string; businessName: string } => { | ||
const additionalInfo = { firstName: '', lastName: '', businessName: '' } | ||
const additionalInfo = { firstName: "", lastName: "", businessName: "" }; | ||
if (payload.given_name) { | ||
additionalInfo.firstName = payload.given_name | ||
additionalInfo.firstName = payload.given_name; | ||
} | ||
|
||
if (payload.family_name) { | ||
additionalInfo.lastName = payload.family_name | ||
additionalInfo.lastName = payload.family_name; | ||
} | ||
|
||
if ( | ||
provider === 'bceidbusiness' || | ||
(additionalInfo.firstName === '' && additionalInfo.lastName === '') | ||
provider === "bceidbusiness" || | ||
(additionalInfo.firstName === "" && additionalInfo.lastName === "") | ||
) { | ||
const name = payload['custom:idp_display_name'] | ||
const spaceIndex = name.indexOf(' ') | ||
const name = payload["custom:idp_display_name"]; | ||
const spaceIndex = name.indexOf(" "); | ||
if (spaceIndex > 0) { | ||
additionalInfo.lastName = this.splitAtSpace( | ||
payload['custom:idp_display_name'] | ||
)[0].replace(/,/g, '') | ||
payload["custom:idp_display_name"] | ||
)[0].replace(/,/g, ""); | ||
additionalInfo.firstName = this.splitAtSpace( | ||
payload['custom:idp_display_name'] | ||
)[1].replace(/,/g, '') | ||
additionalInfo.businessName = payload['custom:idp_business_name'] | ||
payload["custom:idp_display_name"] | ||
)[1].replace(/,/g, ""); | ||
additionalInfo.businessName = payload["custom:idp_business_name"]; | ||
} | ||
} | ||
|
||
return additionalInfo | ||
} | ||
return additionalInfo; | ||
}; | ||
|
||
private splitAtSpace = (name: string): string[] => { | ||
const nameArray = name.split(' ') | ||
const nameArrayWithoutSpaces = nameArray.filter((name) => name !== '') | ||
return nameArrayWithoutSpaces | ||
} | ||
const nameArray = name.split(" "); | ||
const nameArrayWithoutSpaces = nameArray.filter((name) => name !== ""); | ||
return nameArrayWithoutSpaces; | ||
}; | ||
|
||
private loadUser = (): void => { | ||
const accessToken = this.getCookie('idToken') | ||
const accessToken = this.getCookie("idToken"); | ||
if (accessToken) { | ||
const parsedUser = this.parseJwt(accessToken) | ||
const parsedUser = this.parseJwt(accessToken); | ||
this.user = { | ||
name: parsedUser['custom:idp_display_name'], | ||
provider: parsedUser['custom:idp_name'], | ||
userId: parsedUser['custom:idp_user_id'], | ||
name: parsedUser["custom:idp_display_name"], | ||
provider: parsedUser["custom:idp_name"], | ||
userId: parsedUser["custom:idp_user_id"], | ||
birthDate: parsedUser["birthdate"], | ||
email: parsedUser.email, | ||
...this.processName( | ||
parsedUser, | ||
parsedUser['custom:idp_name'] | ||
) | ||
} | ||
this.user.provider = this.user.provider.startsWith('ca.bc.gov.flnr.fam.') ? 'bcsc' : this.user.provider | ||
...this.processName(parsedUser, parsedUser["custom:idp_name"]), | ||
}; | ||
this.user.provider = this.user.provider.startsWith("ca.bc.gov.flnr.fam.") | ||
? "bcsc" | ||
: this.user.provider; | ||
} | ||
} | ||
}; | ||
|
||
private getCookie = (name:string): string | null => { | ||
const cookieString = document.cookie | ||
if (cookieString !== '') { | ||
const cookies = cookieString.split(';') | ||
private getCookie = (name: string): string | null => { | ||
const cookieString = document.cookie; | ||
if (cookieString !== "") { | ||
const cookies = cookieString.split(";"); | ||
for (const cookie of cookies) { | ||
const [cookieName, cookieValue] = cookie.trim().split('=') | ||
const [cookieName, cookieValue] = cookie.trim().split("="); | ||
if (cookieName === name) { | ||
return decodeURIComponent(cookieValue) | ||
return decodeURIComponent(cookieValue); | ||
} | ||
} | ||
} | ||
return null | ||
} | ||
return null; | ||
}; | ||
|
||
private parseJwt = (token: string): any => { | ||
const base64Url = token.split('.')[1] | ||
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/') | ||
const decodedPayload = JSON.parse(atob(base64)) | ||
return decodedPayload | ||
} | ||
const base64Url = token.split(".")[1]; | ||
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/"); | ||
const decodedPayload = JSON.parse(atob(base64)); | ||
return decodedPayload; | ||
}; | ||
} | ||
|
||
export default new ForestClientUserSession() | ||
export default new ForestClientUserSession(); |