Skip to content

Commit

Permalink
Merge pull request #127 from SocialGouv/fix/minor-fixes
Browse files Browse the repository at this point in the history
fix: minor fixes
  • Loading branch information
ClementNumericite authored Nov 12, 2024
2 parents cac77e3 + 37980fc commit 476261f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 23 deletions.
1 change: 1 addition & 0 deletions webapp/src/components/forms/FormInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const FormInput = ({
{...restInputProps}
autoFocus={autoFocus}
type={kind}
{...(kind === "number" && { pattern: "[0-9]*" })}
placeholder={placeholder}
borderRadius={16}
border="none"
Expand Down
1 change: 1 addition & 0 deletions webapp/src/components/obiz/DiscountAmountBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ const DiscountAmountBlock = (props: DiscountAmountBlockProps) => {
>
<Input
type="number"
pattern="[0-9]*"
variant="unstyled"
bgColor={isInvalidDebounce ? "errorLight" : "bgGray"}
borderRadius="2.5xl"
Expand Down
57 changes: 42 additions & 15 deletions webapp/src/pages/dashboard/order/[id]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,38 @@ export default function OrderObizPage() {
order.status !== "delivered" &&
isOlderThan24Hours(order.createdAt);

const showPDF = () => {
if (order.ticket && typeof order.ticket === "object" && order.ticket.url) {
window.open(order.ticket.url, "_blank", "noopener,noreferrer");
}
};
const handlePDFActions = async (isShare: boolean) => {
if (typeof order.ticket === "object" && order.ticket?.url) {
try {
const response = await fetch(order.ticket.url);
const blob = await response.blob();
const filename = `bon-${order.offer.partner.name}-${order.number}.pdf`;

const downloadPDF = () => {
if (order.ticket && typeof order.ticket === "object" && order.ticket.url) {
const link = document.createElement("a");
link.href = order.ticket.url;
link.download = "";
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
const file = new File([blob], filename, {
type: response.headers.get("content-type") || "application/pdf",
});

if (
isShare &&
navigator.share &&
navigator.canShare({ files: [file] })
) {
await navigator.share({
files: [file],
});
} else {
const downloadUrl = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(downloadUrl);
}
} catch (error) {
console.error("Error sharing file:", error);
}
}
};

Expand Down Expand Up @@ -316,7 +334,14 @@ export default function OrderObizPage() {
</Flex>
<Flex justifyContent={"center"} gap={8} mt={8}>
<Box textAlign={"center"}>
<Button colorScheme="blackBtn" p={5} h="auto" onClick={showPDF}>
<Button
colorScheme="blackBtn"
p={5}
h="auto"
onClick={() => {
handlePDFActions(false);
}}
>
<HiEye fontSize={24} />
</Button>
<Text fontWeight={900} fontSize="sm" mt={1}>
Expand All @@ -329,7 +354,9 @@ export default function OrderObizPage() {
flexGrow={0}
p={5}
h="auto"
onClick={downloadPDF}
onClick={() => {
handlePDFActions(true);
}}
>
<MdOutlineFileDownload fontSize={24} />
</Button>
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/pages/dashboard/search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export default function DashboardSearch() {
))}
</Box>
)}
{!!debouncedSearch && (
{!!debouncedSearch && !partners.length && (
<Box mt={12}>
<Text color="disabled" textAlign="center" px={20}>
Nous n'avons pas
Expand Down
8 changes: 1 addition & 7 deletions webapp/src/server/api/routers/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,13 +348,7 @@ export const orderRouter = createTRPCRouter({
collection: "orders",
depth: 3,
where: {
and: [
{ user: { equals: ctx.session.id } },
{ ...statusQuery },
{
...payloadWhereOfferIsValid("offer"),
},
],
and: [{ user: { equals: ctx.session.id } }, { ...statusQuery }],
},
});

Expand Down

0 comments on commit 476261f

Please sign in to comment.