Skip to content

Commit

Permalink
feat: begin component discount amount blocks for order kind of offer
Browse files Browse the repository at this point in the history
  • Loading branch information
HoreKk committed Nov 4, 2024
1 parent 81148b2 commit bc6d2d0
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 6 deletions.
6 changes: 5 additions & 1 deletion webapp/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ WEB_PUSH_PRIVATE_KEY=web-push-private-key
# Widget
NEXT_PUBLIC_WIDGET_TOKEN_NAME=widget-token
WIDGET_SECRET_JWT=secret1
WIDGET_SECRET_DATA_ENCRYPTION=secret2
WIDGET_SECRET_DATA_ENCRYPTION=secret2

# Obiz API
OBIZ_PARTNER_ID=default
OBIZ_SECRET=default
119 changes: 119 additions & 0 deletions webapp/src/components/obiz/DiscountAmountBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import {
Center,
Divider,
Flex,
FormControl,
FormLabel,
Input,
NumberInput,
NumberInputField,
Text,
} from "@chakra-ui/react";
import { Dispatch, SetStateAction } from "react";

const DiscountAmountBlock = ({
amount,
setAmount,
minAmount,
maxAmount,
discount,
}: {
amount: number;
setAmount: Dispatch<SetStateAction<number>>;
minAmount: number;
maxAmount: number;
discount: number;
}) => {
const isDisabled = amount === 0;
const isInvalid =
!isDisabled &&
(amount < minAmount || amount > maxAmount || amount % 1 !== 0);

return (
<Center flexDir="column">
<Flex display="flex" flexDir="column" alignItems="center" mx={10}>
<FormLabel
textAlign="center"
color="disabled"
mx={0}
mb={3}
fontSize={14}
fontWeight={500}
>
Choisissez le montant du bon
</FormLabel>
<Input
type="number"
variant="unstyled"
bgColor={isInvalid ? "errorLight" : "bgGray"}
borderRadius="2.5xl"
fontWeight={800}
textAlign="center"
fontSize="52px"
w="200px"
py={6}
autoComplete="off"
step={1}
onChange={(e) =>
setAmount(e.target.value ? Number(e.target.value) : 0)
}
placeholder="0€"
min={minAmount}
max={maxAmount}
/>
</Flex>
<Flex alignItems="center" mt={6}>
<Center flexDir="column">
<Text fontSize={14} fontWeight={500}>
Vous payez
</Text>
<Flex alignItems="center" gap={2}>
{!isDisabled && (
<Text
fontSize={18}
fontWeight={500}
textDecoration="line-through"
textDecorationThickness="2px"
color="disabled"
>
{amount}
</Text>
)}
<Text
fontSize={24}
fontWeight={800}
opacity={isDisabled ? 0.25 : 1}
>
{(amount - amount * (discount / 100))
.toFixed(isDisabled ? 0 : 2)
.replace(".", ",")}
</Text>
</Flex>
</Center>
<Divider orientation="vertical" h="50px" mx={6} />
<Center flexDir="column">
<Text fontSize={14} fontWeight={500}>
Vous économisez
</Text>
<Text
bgColor={isDisabled ? "black" : "primaryShades.100"}
color={isDisabled ? "white" : "primary"}
borderRadius="2xl"
px={2}
fontSize={24}
fontWeight={800}
opacity={isDisabled ? 0.25 : 1}
>
{(amount * (discount / 100))
.toFixed(isDisabled ? 0 : 2)
.replace(".", ",")}
</Text>
</Center>
</Flex>
</Center>
);
};

export default DiscountAmountBlock;
26 changes: 26 additions & 0 deletions webapp/src/pages/dashboard/obiz-offer-variable.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Box, Button, Flex } from "@chakra-ui/react";
import { useState } from "react";
import DiscountAmountBlock from "~/components/obiz/DiscountAmountBlock";
import BackButton from "~/components/ui/BackButton";

export default function ObizOfferVariable() {
const [amount, setAmount] = useState(0);

return (
<Flex flexDir="column" mt={10} px={8}>
<BackButton />
<Box mt={8}>
<DiscountAmountBlock
discount={5}
amount={amount}
setAmount={setAmount}
minAmount={5}
maxAmount={100}
/>
</Box>
<Button mt={10} onClick={() => setAmount(10)}>
Acheter mon bon
</Button>
</Flex>
);
}
14 changes: 9 additions & 5 deletions webapp/src/server/api/routers/order.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { z } from "zod";
import { createTRPCRouter, userProtectedProcedure } from "~/server/api/trpc";
import { createOrderPayload } from "~/utils/obiz";

export const orderRouter = createTRPCRouter({
createOrder: userProtectedProcedure.query(async ({ ctx }) => {
// const [test] = await ctx.soapObizClient.ETAT_SITEAsync();
createOrder: userProtectedProcedure
.input(z.object({ user_id: z.number(), client_id: z.number() }))
.query(async ({ ctx, input }) => {
const order_payload = createOrderPayload(input);

// console.log(JSON.stringify(test, null, 2));
const [] = await ctx.soapObizClient.CREATION_COMMANDE_ARRAYAsync();

return { data: "Hello" };
}),
return { data: "Hello" };
}),
});
12 changes: 12 additions & 0 deletions webapp/src/utils/obiz.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var crypto = require("crypto");

export const obiz_signature = crypto
.createHash("sha512")
.update(`${process.env.OBIZ_PARTNER_ID}+${process.env.OBIZ_PARTNER_SECRET}`)
.digest("hex") as string;

export const createOrderPayload = async ({ user_id }: { user_id: number }) => {
return {
CE_ID: "",
};
};

0 comments on commit bc6d2d0

Please sign in to comment.