Merge branch 'dev' into staging
This commit is contained in:
commit
a8e757f5da
@ -3,7 +3,7 @@
|
|||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev -p 5005",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"lint": "next lint",
|
"lint": "next lint",
|
||||||
|
@ -38,8 +38,6 @@ export default class Stripe extends BaseAdmin {
|
|||||||
public async post(body: IPostStripeParams) {
|
public async post(body: IPostStripeParams) {
|
||||||
const url = new URL(this.baseURl);
|
const url = new URL(this.baseURl);
|
||||||
try {
|
try {
|
||||||
console.log(body);
|
|
||||||
|
|
||||||
return await this.postRequest<IPostStripeResponse>(url, body as any);
|
return await this.postRequest<IPostStripeResponse>(url, body as any);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.onError(err);
|
this.onError(err);
|
||||||
@ -48,8 +46,6 @@ export default class Stripe extends BaseAdmin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async getClientPortalSession(stripe_subscription_id: string) {
|
public async getClientPortalSession(stripe_subscription_id: string) {
|
||||||
console.log(stripe_subscription_id);
|
|
||||||
|
|
||||||
const url = new URL(this.baseURl.concat(`/${stripe_subscription_id}`));
|
const url = new URL(this.baseURl.concat(`/${stripe_subscription_id}`));
|
||||||
try {
|
try {
|
||||||
return await this.getRequest<IGetClientPortalSessionResponse>(url);
|
return await this.getRequest<IGetClientPortalSessionResponse>(url);
|
||||||
|
@ -5,6 +5,10 @@ export interface IPostSubscriptionsParams {
|
|||||||
emails: string[];
|
emails: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IPutSubscriptionsParams {
|
||||||
|
seats: any;
|
||||||
|
}
|
||||||
|
|
||||||
export default class Subscriptions extends BaseAdmin {
|
export default class Subscriptions extends BaseAdmin {
|
||||||
private static instance: Subscriptions;
|
private static instance: Subscriptions;
|
||||||
private readonly baseURl = this.namespaceUrl.concat("/subscriptions");
|
private readonly baseURl = this.namespaceUrl.concat("/subscriptions");
|
||||||
@ -34,7 +38,7 @@ export default class Subscriptions extends BaseAdmin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description : Create a Document
|
* @description : Invite collaborators to a subscription
|
||||||
*/
|
*/
|
||||||
public async post(body: IPostSubscriptionsParams) {
|
public async post(body: IPostSubscriptionsParams) {
|
||||||
const url = new URL(this.baseURl.concat(`/invite`));
|
const url = new URL(this.baseURl.concat(`/invite`));
|
||||||
@ -45,4 +49,17 @@ export default class Subscriptions extends BaseAdmin {
|
|||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description : Update a Subscription
|
||||||
|
*/
|
||||||
|
public async put(uid: string, body: IPutSubscriptionsParams) {
|
||||||
|
const url = new URL(this.baseURl.concat(`/${uid}`));
|
||||||
|
try {
|
||||||
|
return await this.putRequest(url, body as any);
|
||||||
|
} catch (err) {
|
||||||
|
this.onError(err);
|
||||||
|
return Promise.reject(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,78 +8,37 @@ import React, { useCallback, useEffect, useState } from "react";
|
|||||||
import User, { Subscription } from "le-coffre-resources/dist/Admin";
|
import User, { Subscription } from "le-coffre-resources/dist/Admin";
|
||||||
import JwtService from "@Front/Services/JwtService/JwtService";
|
import JwtService from "@Front/Services/JwtService/JwtService";
|
||||||
import Subscriptions from "@Front/Api/LeCoffreApi/Admin/Subscriptions/Subscriptions";
|
import Subscriptions from "@Front/Api/LeCoffreApi/Admin/Subscriptions/Subscriptions";
|
||||||
|
import Users from "@Front/Api/LeCoffreApi/Admin/Users/Users";
|
||||||
|
import { useRouter } from "next/router";
|
||||||
|
|
||||||
export default function SubscriptionManageCollaborators() {
|
export default function SubscriptionManageCollaborators() {
|
||||||
|
const router = useRouter();
|
||||||
const [subscription, setSubscription] = useState<Subscription | null>(null);
|
const [subscription, setSubscription] = useState<Subscription | null>(null);
|
||||||
const [availableCollaborators, _setAvailableCollaborators] = useState<User[]>([
|
const [availableCollaborators, _setAvailableCollaborators] = useState<User[]>([]);
|
||||||
{
|
|
||||||
created_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
uid: "1",
|
|
||||||
idNot: "1",
|
|
||||||
updated_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
contact: {
|
|
||||||
civility: "M",
|
|
||||||
created_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
email: "jean.dupont@gmail.com",
|
|
||||||
first_name: "Jean",
|
|
||||||
last_name: "Dupont",
|
|
||||||
updated_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
created_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
uid: "2",
|
|
||||||
idNot: "1",
|
|
||||||
updated_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
contact: {
|
|
||||||
civility: "M",
|
|
||||||
created_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
email: "jean.dupont@gmail.com",
|
|
||||||
first_name: "Jean",
|
|
||||||
last_name: "Dupont",
|
|
||||||
updated_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
{
|
|
||||||
created_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
uid: "3",
|
|
||||||
idNot: "1",
|
|
||||||
updated_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
contact: {
|
|
||||||
civility: "M",
|
|
||||||
created_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
email: "jean.dupont@gmail.com",
|
|
||||||
first_name: "Jean",
|
|
||||||
last_name: "Dupont",
|
|
||||||
updated_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
created_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
uid: "4",
|
|
||||||
idNot: "1",
|
|
||||||
updated_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
contact: {
|
|
||||||
civility: "M",
|
|
||||||
created_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
email: "jean.dupont@gmail.com",
|
|
||||||
first_name: "Jean",
|
|
||||||
last_name: "Dupont",
|
|
||||||
updated_at: new Date("2021-09-29T14:00:00.000Z"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
const [selectedCollaborators, setSelectedCollaborators] = useState<string[]>([]);
|
const [selectedCollaborators, setSelectedCollaborators] = useState<string[]>([]);
|
||||||
|
|
||||||
const loadSubscription = useCallback(async () => {
|
const loadSubscription = useCallback(async () => {
|
||||||
const jwt = JwtService.getInstance().decodeJwt();
|
const jwt = JwtService.getInstance().decodeJwt();
|
||||||
const subscription = await Subscriptions.getInstance().get({ where: { office: { uid: jwt?.office_Id } } });
|
const subscription = await Subscriptions.getInstance().get({
|
||||||
|
where: { office: { uid: jwt?.office_Id } },
|
||||||
|
include: { seats: { include: { user: true } } },
|
||||||
|
});
|
||||||
if (!subscription[0]) return;
|
if (!subscription[0]) return;
|
||||||
subscription[0].seats?.forEach((seat) => setSelectedCollaborators((prev) => [...prev, seat.user.uid!]));
|
subscription[0].seats?.forEach((seat) => setSelectedCollaborators((prev) => [...prev, seat.user.uid!]));
|
||||||
setSubscription(subscription[0]);
|
setSubscription(subscription[0]);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const loadCollaborators = useCallback(async () => {
|
||||||
|
const collaborators = await Users.getInstance().get({
|
||||||
|
where: { office_membership: { uid: JwtService.getInstance().getUserJwtPayload()?.office_Id } },
|
||||||
|
include: {
|
||||||
|
contact: true,
|
||||||
|
seats: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
_setAvailableCollaborators(collaborators);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleChange = useCallback(
|
const handleChange = useCallback(
|
||||||
(event: React.ChangeEvent<HTMLInputElement>) => {
|
(event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
if (!subscription) return;
|
if (!subscription) return;
|
||||||
@ -100,12 +59,18 @@ export default function SubscriptionManageCollaborators() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
const handleSubmit = async (e: React.FormEvent<HTMLFormElement> | null, values: { [key: string]: string }) => {
|
||||||
|
const subcriptionToUpdate = {
|
||||||
|
seats: selectedCollaborators.map((collaborator) => ({ user: { uid: collaborator } })),
|
||||||
|
};
|
||||||
|
await Subscriptions.getInstance().put(subscription?.uid!, subcriptionToUpdate);
|
||||||
|
router.push("/subscription/manage");
|
||||||
if (!e) return;
|
if (!e) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadSubscription();
|
loadSubscription();
|
||||||
|
loadCollaborators();
|
||||||
}, [loadSubscription]);
|
}, [loadSubscription]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -141,7 +106,7 @@ export default function SubscriptionManageCollaborators() {
|
|||||||
{selectedCollaborators.length} collaborateurs sélectionnés
|
{selectedCollaborators.length} collaborateurs sélectionnés
|
||||||
</Typography>
|
</Typography>
|
||||||
<div className={classes["buttons-container"]}>
|
<div className={classes["buttons-container"]}>
|
||||||
<Button variant={EButtonVariant.PRIMARY} fullwidth>
|
<Button type="submit" variant={EButtonVariant.PRIMARY} fullwidth>
|
||||||
Enregistrer
|
Enregistrer
|
||||||
</Button>
|
</Button>
|
||||||
<Button variant={EButtonVariant.GHOST} fullwidth onClick={cancelAll} type="button">
|
<Button variant={EButtonVariant.GHOST} fullwidth onClick={cancelAll} type="button">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user