cloudinary-community / next-cloudinary

⚡️ High-performance image delivery and uploading at scale in Next.js powered by Cloudinary.
https://next.cloudinary.dev
MIT License
237 stars 64 forks source link

added onSuccessAction prop to Upload Widget #487

Open JoshuaRotimi opened 1 week ago

JoshuaRotimi commented 1 week ago

Description

This PR adds an onSuccessAction prop to the CloudUploadWidget component.

Issue Ticket Number

Fixes # Issue 486

Fixes: https://github.com/cloudinary-community/next-cloudinary/issues/486

Type of change

vercel[bot] commented 1 week ago

@JoshuaRotimi is attempting to deploy a commit to the Cloudinary DevX Team on Vercel.

A member of the Team first needs to authorize it.

colbyfayock commented 1 week ago

hey @JoshuaRotimi thanks for putting this together. have a few requests:

image
const widgetEvent = WIDGET_EVENTS[uploadResult.event] as keyof typeof props;

if ( typeof widgetEvent === 'string' && typeof props[widgetEvent] === 'function' ) {
  const callback = props[widgetEvent] as CldUploadEventCallback;
  callback(uploadResult, {
    widget: widget.current,
    ...instanceMethods
  });
}

it's not unreasonable to think that we could add onto that by doing osmething like:

const widgetEventAction = typeof widgetEvent === 'string' && `${widgetEvent}Action`;

if ( widgetEventAction && typeof props[widgetEventAction] === 'function' ) {
  const action = props[widgetEventAction] as CldUploadEventAction;
  onSuccessAction(uploadResult);
}

wdyt?

JoshuaRotimi commented 1 week ago

Hello @colbyfayock

Okay, I will add more information about the feature to the PR.

About the JSON/FormData, I think we could switch to JSON, it makes the code more readable without the Object.entries loop, I thought you may have had a definite reason why FormData was the best option.

If we want to automate the action creation the way you stated, we would have to add types for all the other instances like onDisplayChangedAction, onUploadAddedAction and the rest of the CloudWidgetProps actions. is that what we want to do?

Okay, I can add the same functionality to the CloudUploadButton once we have it working correctly for the CloudUploadWidget.