Skip to content
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
21 changes: 0 additions & 21 deletions __tests__/lib/getToken.test.tsx

This file was deleted.

13 changes: 13 additions & 0 deletions example/nextjs/pages/_app.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Script from 'next/script';
import '../../../dist/promo-button.esm.css'; // @tincre/promo-button/bundle.css

function MyApp({ Component, pageProps }) {
return (
<>
<Script src="https://upload-widget.cloudinary.com/global/all.js" />
<Component {...pageProps} />
</>
);
}

export default MyApp;
157 changes: 88 additions & 69 deletions example/nextjs/yarn.lock

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
"@types/jest": "^28.1.6",
"@types/jsonwebtoken": "^8.5.8",
"@types/node": "^17.0.25",
"@types/react": "^18.0.6",
"@types/react-dom": "^18.0.2",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
"@typescript-eslint/eslint-plugin": "^5.20.0",
"@typescript-eslint/parser": "^5.20.0",
"autoprefixer": "10.4.5",
Expand All @@ -107,8 +107,8 @@
"jsonwebtoken": "^9.0.2",
"postcss": "^8.4.31",
"prettier": "^2.6.2",
"react": "~17",
"react-dom": "~17",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rollup-plugin-import-css": "^3.0.3",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-svg": "^2.0.0",
Expand All @@ -119,7 +119,6 @@
"typescript": "^4.6.3"
},
"dependencies": {
"@tincre/promo-node": "^0.1.0",
"@tincre/promo-types": ">=0.0.3"
},
"keywords": [
Expand Down
2 changes: 1 addition & 1 deletion src/components/Cloudinary/Cloudinary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { CloudinaryOptions } from '@tincre/promo-types';
import { getWidget, showWidget } from '@tincre/promo-node';
import { getWidget, showWidget } from '../../lib/cloudinary-utils';

export default function Cloudinary({
setFileImage,
Expand Down
2 changes: 1 addition & 1 deletion src/components/DefaultAdDisplay/DefaultAdDisplay.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { detectMediaType } from '@tincre/promo-node';
import { detectMediaType } from '../../lib/utils';
import AdDisplay from '../AdDisplay/AdDisplay';

interface MediaObject {
Expand Down
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import React, {
} from 'react';

import { Dialog, Transition } from '@headlessui/react';
import { getToken, generateAccessToken, getOptions } from '@tincre/promo-node';
import { getOptions } from './lib/utils';
import { Options } from './lib/types';
import { PromoOptions, ButtonFormSubmission } from '@tincre/promo-types';
import HowItWorks from './components/HowItWorks/HowItWorks';
Expand Down Expand Up @@ -392,4 +392,4 @@ function PromoButton({
);
}

export { PromoButton, getToken, generateAccessToken, DefaultAdDisplay };
export { PromoButton, DefaultAdDisplay };
37 changes: 37 additions & 0 deletions src/lib/cloudinary-utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { CloudinaryOptions } from '@tincre/promo-types';

export function getWidgetCallback(
setFileImage: any,
fileImage: any,
error: any,
result: any
) {
if (!error && result && result.event === 'success') {
if (!fileImage) {
setFileImage([{ ...result.info }]);
} else {
setFileImage([...fileImage, { ...result.info }]);
}
}
if (error) {
console.error(error.message);
}
}
export function getWidget(
setFileImage: any,
fileImage: object,
cloudinaryOptions: CloudinaryOptions
) {
if (typeof window.cloudinary === 'undefined') return null;
let options = cloudinaryOptions;
let widget = window.cloudinary.createUploadWidget(
options,
(error: any, result: any) =>
getWidgetCallback(setFileImage, fileImage, error, result)
);
return widget;
}
export function showWidget(widget: any) {
if (typeof window.cloudinary === 'undefined') return null;
widget.open();
}
Loading