Compare commits
33 Commits
fix_demo_8
...
main
Author | SHA1 | Date | |
---|---|---|---|
![]() |
186f8f1075 | ||
![]() |
59920f0ef4 | ||
![]() |
310634c930 | ||
![]() |
e87b1ddde5 | ||
![]() |
b63973a9ba | ||
![]() |
2d28f1a21a | ||
![]() |
20a333c106 | ||
3048e8788e | |||
67fa4c923d | |||
a916a66747 | |||
a8f2d8ed75 | |||
![]() |
1621bc1d53 | ||
![]() |
f55b495449 | ||
![]() |
7ffbe26d2b | ||
![]() |
c34659902e | ||
![]() |
ea3d2d8e8d | ||
affa234d65 | |||
a0ac83bf2f | |||
![]() |
3ba6dd767d | ||
![]() |
36e1bae353 | ||
![]() |
aa3feb4f14 | ||
![]() |
1766dc5a75 | ||
![]() |
bb370900bd | ||
![]() |
7065f07373 | ||
c313f6b493 | |||
ddf6c6c79d | |||
b632729796 | |||
ece4738b44 | |||
21ea67e1c1 | |||
ef4f8ac2bc | |||
05ffd14447 | |||
ae047c9485 | |||
b94037e4a5 |
24
.github/workflows/prd.yml
vendored
24
.github/workflows/prd.yml
vendored
@ -1,8 +1,8 @@
|
||||
name: Prod - Build & Deploy to Scaleway
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main]
|
||||
push:
|
||||
branches: [main]
|
||||
|
||||
env:
|
||||
|
||||
@ -18,16 +18,16 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup SSH
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
- name: Copy SSH
|
||||
run: cp ~/.ssh/id_rsa id_rsa
|
||||
#- name: Setup SSH
|
||||
# run: |
|
||||
# mkdir -p ~/.ssh
|
||||
# echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||
# chmod 600 ~/.ssh/id_rsa
|
||||
# ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
|
||||
# env:
|
||||
# SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
#- name: Copy SSH
|
||||
# run: cp ~/.ssh/id_rsa id_rsa
|
||||
- name: Login to Scaleway Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
|
74
.github/workflows/test.yml
vendored
Normal file
74
.github/workflows/test.yml
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
name: Test - Build & Deploy to Scaleway
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [legacy_dev]
|
||||
|
||||
env:
|
||||
PROJECT_ID_LECOFFRE: 72d08499-37c2-412b-877e-f8af0471654a
|
||||
NAMESPACE_ID_LECOFFRE: 3829c5cd-9fb0-4871-97a1-eb33e4bc1114
|
||||
CONTAINER_REGISTRY_ENDPOINT_LECOFFRE: rg.fr-par.scw.cloud/funcscwlecoffretestouylprmj
|
||||
|
||||
IMAGE_NAME: front
|
||||
CONTAINER_NAME: front
|
||||
|
||||
jobs:
|
||||
build-and-push-image-lecoffre:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Setup SSH
|
||||
run: |
|
||||
mkdir -p ~/.ssh
|
||||
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
|
||||
chmod 600 ~/.ssh/id_rsa
|
||||
ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
- name: Copy SSH
|
||||
run: cp ~/.ssh/id_rsa id_rsa
|
||||
- name: Login to Scaleway Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: nologin
|
||||
password: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
|
||||
registry: ${{ env.CONTAINER_REGISTRY_ENDPOINT_LECOFFRE }}
|
||||
- name: Build the Docker Image
|
||||
run: docker build . -t ${{ env.CONTAINER_REGISTRY_ENDPOINT_LECOFFRE }}/${{ env.IMAGE_NAME }}
|
||||
- name: Push the Docker Image to Scaleway Container Registry
|
||||
run: docker push ${{ env.CONTAINER_REGISTRY_ENDPOINT_LECOFFRE }}/${{ env.IMAGE_NAME }}
|
||||
deploy-to-scaleway-lecoffre:
|
||||
needs: build-and-push-image-lecoffre
|
||||
runs-on: ubuntu-latest
|
||||
environment: test
|
||||
steps:
|
||||
- name: Install CLI
|
||||
uses: scaleway/action-scw@v0
|
||||
- name: Get container ID
|
||||
run: |
|
||||
echo "CONTAINER_ID=$(scw container container list namespace-id=${{env.NAMESPACE_ID_LECOFFRE}} -o json | jq -r '.[] | select(.name == "${{ env.CONTAINER_NAME }}") | .id')" >> $GITHUB_ENV
|
||||
env:
|
||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY_LECOFFRE }}
|
||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
|
||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID_LECOFFRE }}
|
||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID_LECOFFRE }}
|
||||
- name: Deploy the container based on the new image
|
||||
run: |
|
||||
env_string=""
|
||||
while IFS= read -r line; do
|
||||
if [[ "$line" == *"="* ]]; then
|
||||
key=$(echo "$line" | cut -d '=' -f 1)
|
||||
value=$(echo "$line" | cut -d '=' -f 2-)
|
||||
if [[ -n "$key" ]]; then
|
||||
env_string+="environment-variables.$key=$value "
|
||||
fi
|
||||
fi
|
||||
done <<< "$ENV_VARS"
|
||||
env_string=$(echo $env_string | sed 's/ $//')
|
||||
scw container container update ${{ env.CONTAINER_ID }} $env_string
|
||||
env:
|
||||
ENV_VARS: ${{ secrets.ENV }}
|
||||
SCW_ACCESS_KEY: ${{ secrets.SCW_ACCESS_KEY_LECOFFRE }}
|
||||
SCW_SECRET_KEY: ${{ secrets.SCW_SECRET_KEY_LECOFFRE }}
|
||||
SCW_DEFAULT_PROJECT_ID: ${{ env.PROJECT_ID_LECOFFRE }}
|
||||
SCW_DEFAULT_ORGANIZATION_ID: ${{ secrets.SCW_ORGANIZATION_ID_LECOFFRE }}
|
@ -7,10 +7,10 @@ COPY package.json ./
|
||||
|
||||
RUN apk update && apk add openssh-client git
|
||||
|
||||
COPY id_rsa /root/.ssh/id_rsa
|
||||
RUN chmod 600 ~/.ssh/id_rsa
|
||||
RUN eval "$(ssh-agent -s)" && ssh-add /root/.ssh/id_rsa
|
||||
RUN ssh-keyscan github.com smart-chain-fr/leCoffre-resources.git >> /root/.ssh/known_hosts
|
||||
#COPY id_rsa /root/.ssh/id_rsa
|
||||
#RUN chmod 600 ~/.ssh/id_rsa
|
||||
#RUN eval "$(ssh-agent -s)" && ssh-add /root/.ssh/id_rsa
|
||||
#RUN ssh-keyscan github.com smart-chain-fr/leCoffre-resources.git >> /root/.ssh/known_hosts
|
||||
|
||||
RUN npm install --frozen-lockfile
|
||||
|
||||
|
@ -30,7 +30,7 @@
|
||||
"heroicons": "^2.1.5",
|
||||
"jszip": "^3.10.1",
|
||||
"jwt-decode": "^3.1.2",
|
||||
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.167",
|
||||
"le-coffre-resources": "git+https://git.4nkweb.com/4nk/lecoffre-ressources.git#v2.167",
|
||||
"next": "^14.2.3",
|
||||
"prettier": "^2.8.7",
|
||||
"react": "18.2.0",
|
||||
|
@ -30,6 +30,15 @@ export default abstract class BaseApiService {
|
||||
}
|
||||
|
||||
protected buildHeaders(contentType: ContentType) {
|
||||
// Don't try to access cookies during server-side rendering
|
||||
if (typeof window === 'undefined') {
|
||||
const headers = new Headers();
|
||||
if (contentType === ContentType.JSON || contentType === ContentType.PDF) {
|
||||
headers.set("Content-Type", contentType);
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
const token = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
|
||||
const headers = new Headers();
|
||||
@ -37,7 +46,14 @@ export default abstract class BaseApiService {
|
||||
if (contentType === ContentType.JSON || contentType === ContentType.PDF) {
|
||||
headers.set("Content-Type", contentType);
|
||||
}
|
||||
headers.set("Authorization", `Bearer ${token}`);
|
||||
|
||||
// Only set Authorization header if token exists
|
||||
if (token) {
|
||||
headers.set("Authorization", `Bearer ${token}`);
|
||||
} else {
|
||||
console.warn("No access token found in cookies when building headers");
|
||||
}
|
||||
|
||||
return headers;
|
||||
}
|
||||
|
||||
@ -134,38 +150,66 @@ export default abstract class BaseApiService {
|
||||
}
|
||||
|
||||
private async checkJwtToken() {
|
||||
// Don't check tokens during server-side rendering
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
if (!accessToken) return;
|
||||
|
||||
const userDecodedToken = jwt_decode(accessToken) as IUserJwtPayload;
|
||||
const customerDecodedToken = jwt_decode(accessToken) as ICustomerJwtPayload;
|
||||
|
||||
if (!userDecodedToken && !customerDecodedToken) return;
|
||||
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
if (userDecodedToken.userId && userDecodedToken.exp < now) {
|
||||
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
|
||||
if (!refreshToken) {
|
||||
return;
|
||||
}
|
||||
const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload;
|
||||
if (decodedRefreshToken.exp < now) {
|
||||
return;
|
||||
}
|
||||
await JwtService.getInstance().refreshToken(refreshToken);
|
||||
if (!accessToken) {
|
||||
console.warn("No access token found during JWT check");
|
||||
return;
|
||||
}
|
||||
if (customerDecodedToken.customerId && customerDecodedToken.exp < now) {
|
||||
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
|
||||
if (!refreshToken) {
|
||||
|
||||
try {
|
||||
const userDecodedToken = jwt_decode(accessToken) as IUserJwtPayload;
|
||||
const customerDecodedToken = jwt_decode(accessToken) as ICustomerJwtPayload;
|
||||
|
||||
if (!userDecodedToken && !customerDecodedToken) {
|
||||
console.warn("Invalid token format during JWT check");
|
||||
return;
|
||||
}
|
||||
const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload;
|
||||
if (decodedRefreshToken.exp < now) {
|
||||
return;
|
||||
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
|
||||
if (userDecodedToken.userId && userDecodedToken.exp < now) {
|
||||
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
|
||||
if (!refreshToken) {
|
||||
console.warn("Access token expired but no refresh token found");
|
||||
return;
|
||||
}
|
||||
const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload;
|
||||
if (decodedRefreshToken.exp < now) {
|
||||
console.warn("Both access and refresh tokens are expired");
|
||||
return;
|
||||
}
|
||||
const refreshSuccess = await JwtService.getInstance().refreshToken(refreshToken);
|
||||
if (!refreshSuccess) {
|
||||
console.error("Failed to refresh token");
|
||||
return;
|
||||
}
|
||||
}
|
||||
await JwtService.getInstance().refreshToken(refreshToken);
|
||||
|
||||
if (customerDecodedToken.customerId && customerDecodedToken.exp < now) {
|
||||
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
|
||||
if (!refreshToken) {
|
||||
console.warn("Access token expired but no refresh token found");
|
||||
return;
|
||||
}
|
||||
const decodedRefreshToken = jwt_decode(refreshToken) as IUserJwtPayload | ICustomerJwtPayload;
|
||||
if (decodedRefreshToken.exp < now) {
|
||||
console.warn("Both access and refresh tokens are expired");
|
||||
return;
|
||||
}
|
||||
const refreshSuccess = await JwtService.getInstance().refreshToken(refreshToken);
|
||||
if (!refreshSuccess) {
|
||||
console.error("Failed to refresh token");
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error during JWT token check:", error);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
protected async processResponse<T>(response: Response, request: () => Promise<Response>, ref?: IRef, fileName?: string): Promise<T> {
|
||||
|
@ -313,10 +313,11 @@ export default function DocumentTables(props: IProps) {
|
||||
);
|
||||
|
||||
const progress = useMemo(() => {
|
||||
const total = askedDocuments.length + toValidateDocuments.length + validatedDocuments.length + refusedDocuments.length;
|
||||
// Exclude refused documents from total - only count documents that are still in progress
|
||||
const total = askedDocuments.length + toValidateDocuments.length + validatedDocuments.length;
|
||||
if (total === 0) return 0;
|
||||
return (validatedDocuments.length / total) * 100;
|
||||
}, [askedDocuments.length, refusedDocuments.length, toValidateDocuments.length, validatedDocuments.length]);
|
||||
}, [askedDocuments.length, toValidateDocuments.length, validatedDocuments.length]);
|
||||
|
||||
if (documents.length === 0 && documentsNotary.length === 0) return <NoDocument />;
|
||||
|
||||
|
@ -47,8 +47,10 @@ export default function FolderInformation(props: IProps) {
|
||||
let validatedDocuments = 0;
|
||||
folder?.customers?.forEach((customer) => {
|
||||
const documents = customer.documents;
|
||||
total += documents?.length ?? 0;
|
||||
validatedDocuments += documents?.filter((document) => document.document_status === EDocumentStatus.VALIDATED).length ?? 0;
|
||||
// Only count documents that are not refused (still in progress)
|
||||
const activeDocuments = documents?.filter((document) => document.document_status !== EDocumentStatus.REFUSED) ?? [];
|
||||
total += activeDocuments.length;
|
||||
validatedDocuments += activeDocuments.filter((document) => document.document_status === EDocumentStatus.VALIDATED).length;
|
||||
});
|
||||
if (total === 0) return 0;
|
||||
const percentage = (validatedDocuments / total) * 100;
|
||||
|
@ -83,7 +83,7 @@ export default function StepEmail(props: IProps) {
|
||||
<div className={classes["content"]}>
|
||||
<div className={classes["section"]}>
|
||||
<Typography typo={ETypo.TITLE_H6} color={ETypoColor.TEXT_ACCENT} className={classes["section-title"]}>
|
||||
Pour les notaires et les colaborateurs :
|
||||
Pour les notaires et les collaborateurs :
|
||||
</Typography>
|
||||
<Button onClick={redirectUserOnConnection} rightIcon={<Image alt="id-not-logo" src={idNoteLogo} />}>
|
||||
S'identifier avec ID.not
|
||||
|
@ -1,5 +1,6 @@
|
||||
import Users from "@Front/Api/LeCoffreApi/Notary/Users/Users";
|
||||
import JwtService from "@Front/Services/JwtService/JwtService";
|
||||
import UserStore from "@Front/Stores/UserStore";
|
||||
import User from "le-coffre-resources/dist/Notary";
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
@ -7,8 +8,23 @@ export default function useUser() {
|
||||
const [user, setUser] = useState<User | null>();
|
||||
|
||||
useEffect(() => {
|
||||
// Don't run on server-side
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if user is connected before making API calls
|
||||
if (!UserStore.instance.isConnected()) {
|
||||
console.warn("User not connected, skipping API call");
|
||||
return;
|
||||
}
|
||||
|
||||
const decodedJwt = JwtService.getInstance().decodeJwt();
|
||||
if (!decodedJwt) return;
|
||||
if (!decodedJwt) {
|
||||
console.warn("No valid JWT found, skipping API call");
|
||||
return;
|
||||
}
|
||||
|
||||
Users.getInstance()
|
||||
.getByUid(decodedJwt.userId, {
|
||||
q: {
|
||||
@ -17,6 +33,9 @@ export default function useUser() {
|
||||
})
|
||||
.then((user) => {
|
||||
setUser(user);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Failed to fetch user:", error);
|
||||
});
|
||||
}, []);
|
||||
|
||||
|
@ -9,10 +9,46 @@ export default class UserStore {
|
||||
protected readonly event = new EventEmitter();
|
||||
public accessToken: string | null = null;
|
||||
public refreshToken: string | null = null;
|
||||
private initialized = false;
|
||||
|
||||
private constructor() {}
|
||||
private constructor() {
|
||||
// Don't initialize tokens during server-side rendering
|
||||
if (typeof window !== 'undefined') {
|
||||
this.initializeFromCookies();
|
||||
}
|
||||
}
|
||||
|
||||
private initializeFromCookies() {
|
||||
if (this.initialized) return;
|
||||
|
||||
try {
|
||||
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
|
||||
|
||||
if (accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
if (refreshToken) {
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
this.initialized = true;
|
||||
} catch (error) {
|
||||
console.warn("Failed to initialize tokens from cookies:", error);
|
||||
}
|
||||
}
|
||||
|
||||
public isConnected(): boolean {
|
||||
// Ensure initialization on client side
|
||||
if (typeof window !== 'undefined' && !this.initialized) {
|
||||
this.initializeFromCookies();
|
||||
}
|
||||
|
||||
// Check both instance variable and cookie to ensure consistency
|
||||
if (typeof window !== 'undefined') {
|
||||
const cookieToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
return !!(this.accessToken || cookieToken);
|
||||
}
|
||||
|
||||
return !!this.accessToken;
|
||||
}
|
||||
|
||||
@ -27,6 +63,10 @@ export default class UserStore {
|
||||
CookieService.getInstance().setCookie("leCoffreAccessToken", accessToken);
|
||||
CookieService.getInstance().setCookie("leCoffreRefreshToken", refreshToken);
|
||||
|
||||
// Update instance variables
|
||||
this.accessToken = accessToken;
|
||||
this.refreshToken = refreshToken;
|
||||
|
||||
this.event.emit("connection", this.accessToken);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -41,6 +81,10 @@ export default class UserStore {
|
||||
CookieService.getInstance().deleteCookie("leCoffreAccessToken");
|
||||
CookieService.getInstance().deleteCookie("leCoffreRefreshToken");
|
||||
|
||||
// Clear instance variables
|
||||
this.accessToken = null;
|
||||
this.refreshToken = null;
|
||||
|
||||
this.event.emit("disconnection", this.accessToken);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
@ -9,10 +9,46 @@ export default class UserStore {
|
||||
protected readonly event = new EventEmitter();
|
||||
public accessToken: string | null = null;
|
||||
public refreshToken: string | null = null;
|
||||
private initialized = false;
|
||||
|
||||
private constructor() {}
|
||||
private constructor() {
|
||||
// Don't initialize tokens during server-side rendering
|
||||
if (typeof window !== 'undefined') {
|
||||
this.initializeFromCookies();
|
||||
}
|
||||
}
|
||||
|
||||
private initializeFromCookies() {
|
||||
if (this.initialized) return;
|
||||
|
||||
try {
|
||||
const accessToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
const refreshToken = CookieService.getInstance().getCookie("leCoffreRefreshToken");
|
||||
|
||||
if (accessToken) {
|
||||
this.accessToken = accessToken;
|
||||
}
|
||||
if (refreshToken) {
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
this.initialized = true;
|
||||
} catch (error) {
|
||||
console.warn("Failed to initialize tokens from cookies:", error);
|
||||
}
|
||||
}
|
||||
|
||||
public isConnected(): boolean {
|
||||
// Ensure initialization on client side
|
||||
if (typeof window !== 'undefined' && !this.initialized) {
|
||||
this.initializeFromCookies();
|
||||
}
|
||||
|
||||
// Check both instance variable and cookie to ensure consistency
|
||||
if (typeof window !== 'undefined') {
|
||||
const cookieToken = CookieService.getInstance().getCookie("leCoffreAccessToken");
|
||||
return !!(this.accessToken || cookieToken);
|
||||
}
|
||||
|
||||
return !!this.accessToken;
|
||||
}
|
||||
|
||||
@ -27,6 +63,10 @@ export default class UserStore {
|
||||
CookieService.getInstance().setCookie("leCoffreAccessToken", accessToken);
|
||||
CookieService.getInstance().setCookie("leCoffreRefreshToken", refreshToken);
|
||||
|
||||
// Update instance variables
|
||||
this.accessToken = accessToken;
|
||||
this.refreshToken = refreshToken;
|
||||
|
||||
this.event.emit("connection", this.accessToken);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
@ -41,6 +81,10 @@ export default class UserStore {
|
||||
CookieService.getInstance().deleteCookie("leCoffreAccessToken");
|
||||
CookieService.getInstance().deleteCookie("leCoffreRefreshToken");
|
||||
|
||||
// Clear instance variables
|
||||
this.accessToken = null;
|
||||
this.refreshToken = null;
|
||||
|
||||
this.event.emit("disconnection", this.accessToken);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
Loading…
x
Reference in New Issue
Block a user