Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: minor fixes #127

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -346,13 +346,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
Loading