Update return type for Facebook verification
This commit is contained in:
parent
f6dc60eb08
commit
e22a8e8d98
7 changed files with 939 additions and 475 deletions
1312
package-lock.json
generated
1312
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -6,6 +6,7 @@ import { useRouter } from "next/navigation";
|
||||||
import { DisplayTextField, Button, Dialog, colors, typography } from "ui";
|
import { DisplayTextField, Button, Dialog, colors, typography } from "ui";
|
||||||
import { Selectable } from "kysely";
|
import { Selectable } from "kysely";
|
||||||
import { type Database } from "bridge-common";
|
import { type Database } from "bridge-common";
|
||||||
|
import { QRCode } from "./QRCode";
|
||||||
import { generateDeleteAction } from "../lib/actions";
|
import { generateDeleteAction } from "../lib/actions";
|
||||||
import { serviceConfig } from "../config/config";
|
import { serviceConfig } from "../config/config";
|
||||||
import { FieldDescription } from "../lib/service";
|
import { FieldDescription } from "../lib/service";
|
||||||
|
|
@ -70,6 +71,16 @@ export const Detail: FC<DetailProps> = ({ service, row }) => {
|
||||||
<Grid container direction="row" rowSpacing={3} columnSpacing={2}>
|
<Grid container direction="row" rowSpacing={3} columnSpacing={2}>
|
||||||
{fields.map((field: FieldDescription) => (
|
{fields.map((field: FieldDescription) => (
|
||||||
<Grid item xs={field.size ?? 6} key={field.name}>
|
<Grid item xs={field.size ?? 6} key={field.name}>
|
||||||
|
{field.kind === "qrcode" && (
|
||||||
|
<QRCode
|
||||||
|
name={field.name}
|
||||||
|
label={field.label}
|
||||||
|
getValue={field.getValue}
|
||||||
|
id={row["id"] as string}
|
||||||
|
helperText={field.helperText}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
{(!field.kind || field.kind === "text") && (
|
||||||
<DisplayTextField
|
<DisplayTextField
|
||||||
name={field.name}
|
name={field.name}
|
||||||
label={field.label}
|
label={field.label}
|
||||||
|
|
@ -77,6 +88,7 @@ export const Detail: FC<DetailProps> = ({ service, row }) => {
|
||||||
value={row[field.name] as string}
|
value={row[field.name] as string}
|
||||||
copyable={field.copyable ?? false}
|
copyable={field.copyable ?? false}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</Grid>
|
</Grid>
|
||||||
))}
|
))}
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
|
||||||
42
packages/bridge-ui/components/QRCode.tsx
Normal file
42
packages/bridge-ui/components/QRCode.tsx
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
import { FC, useEffect, useState } from "react";
|
||||||
|
import QRCodeInternal from "react-qr-code";
|
||||||
|
import { Box } from "@mui/material";
|
||||||
|
import { colors } from "../styles/theme";
|
||||||
|
|
||||||
|
type QRCodeProps = {
|
||||||
|
name: string;
|
||||||
|
label: string;
|
||||||
|
id: string;
|
||||||
|
helperText?: string;
|
||||||
|
getValue?: (id: string) => Promise<string>;
|
||||||
|
refreshInterval?: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const QRCode: FC<QRCodeProps> = ({
|
||||||
|
name,
|
||||||
|
label,
|
||||||
|
id,
|
||||||
|
helperText,
|
||||||
|
getValue,
|
||||||
|
refreshInterval,
|
||||||
|
}) => {
|
||||||
|
const [value, setValue] = useState("");
|
||||||
|
const { white } = colors;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (getValue && refreshInterval) {
|
||||||
|
const interval = setInterval(async () => {
|
||||||
|
const result = await getValue(id);
|
||||||
|
setValue(result);
|
||||||
|
}, refreshInterval);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}
|
||||||
|
}, [getValue, refreshInterval]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ backgroundColor: white, m: 2 }}>
|
||||||
|
<QRCodeInternal value={value} />
|
||||||
|
<Box>{helperText}</Box>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
import { ServiceConfig } from "../lib/service";
|
import { ServiceConfig } from "../lib/service";
|
||||||
|
|
||||||
|
const getQRCode = async (id: string) => {
|
||||||
|
console.log("Getting QR code");
|
||||||
|
return "xya"; // "2hVSc9OT18wbo60WLKlVrd5KqQqYZWdH+kVlRYlrnZcKbjbzwcL4ybkS1/jGaN5bLafX9ZaR829xyhQ=";
|
||||||
|
};
|
||||||
|
|
||||||
export const whatsappConfig: ServiceConfig = {
|
export const whatsappConfig: ServiceConfig = {
|
||||||
entity: "whatsapp",
|
entity: "whatsapp",
|
||||||
table: "WhatsappBot",
|
table: "WhatsappBot",
|
||||||
|
|
@ -59,6 +64,15 @@ export const whatsappConfig: ServiceConfig = {
|
||||||
label: "Token",
|
label: "Token",
|
||||||
copyable: true,
|
copyable: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "qrcode",
|
||||||
|
label: "QR Code",
|
||||||
|
kind: "qrcode",
|
||||||
|
size: 4,
|
||||||
|
getValue: getQRCode,
|
||||||
|
helperText: "Go ahead, scan it",
|
||||||
|
refreshInterval: 5,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
listColumns: [
|
listColumns: [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,13 @@ export class Facebook extends Service {
|
||||||
|
|
||||||
if (searchParams.get("hub.mode") === "subscribe") {
|
if (searchParams.get("hub.mode") === "subscribe") {
|
||||||
const challenge = searchParams.get("hub.challenge");
|
const challenge = searchParams.get("hub.challenge");
|
||||||
|
const response = new Response(challenge, { status: 200 });
|
||||||
|
|
||||||
return NextResponse.json(challenge) as any;
|
return response as any;
|
||||||
} else {
|
} else {
|
||||||
return NextResponse.error();
|
return NextResponse.error();
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
const message = await req.json();
|
const message = await req.json();
|
||||||
const worker = await getWorkerUtils();
|
const worker = await getWorkerUtils();
|
||||||
await worker.addJob("facebook/receive-facebook-message", { message });
|
await worker.addJob("facebook/receive-facebook-message", { message });
|
||||||
|
|
@ -30,3 +30,4 @@ export class Facebook extends Service {
|
||||||
return NextResponse.json({ response: "ok" });
|
return NextResponse.json({ response: "ok" });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,9 @@ export type SelectOption = {
|
||||||
export type FieldDescription = {
|
export type FieldDescription = {
|
||||||
name: string;
|
name: string;
|
||||||
label: string;
|
label: string;
|
||||||
kind?: "text" | "phone" | "select" | "multi";
|
kind?: "text" | "phone" | "select" | "multi" | "qrcode";
|
||||||
|
getValue?: (id: string) => Promise<string>;
|
||||||
|
refreshInterval?: number;
|
||||||
getOptions?: (formState: any) => Promise<SelectOption[]>;
|
getOptions?: (formState: any) => Promise<SelectOption[]>;
|
||||||
autogenerated?: "token";
|
autogenerated?: "token";
|
||||||
hidden?: boolean;
|
hidden?: boolean;
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
"react-iframe": "^1.8.5",
|
"react-iframe": "^1.8.5",
|
||||||
"react-markdown": "^9.0.1",
|
"react-markdown": "^9.0.1",
|
||||||
"react-polyglot": "^0.7.2",
|
"react-polyglot": "^0.7.2",
|
||||||
|
"react-qr-code": "^2.0.13",
|
||||||
"tss-react": "^4.9.10",
|
"tss-react": "^4.9.10",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue