1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6007],{6007:(e,t,r)=>{r.r(t),r.d(t,{default:()=>T});var a=r(45185),s=r(52732),o=r(6582),i=r(73791),n=r(3901),l=r(89844),d=r(15228),c=r(65098),u=r(34580),m=r(66710),h=r(70464),f=r(15645),p=r(80113),x=r(94768),y=r(84305),g=r(94959),v=r(69856),j=r(68561),b=r(82746),w=r(12507),U=r(77626),S=r(464),N=r(11357),I=r(11444),R=r(88581),C=r(12717),L=r(72784),F=r(57058),D=r(54708),P=r(29636);let O=(0,N.default)(()=>Promise.all([r.e(61902),r.e(37067),r.e(52850),r.e(45331),r.e(53695),r.e(35841),r.e(99802),r.e(65659),r.e(63075),r.e(9433),r.e(39799),r.e(56401),r.e(30914),r.e(9074),r.e(21746),r.e(95798),r.e(79513),r.e(83023),r.e(902),r.e(12529)]).then(r.bind(r,83023)),{loadableGenerated:{webpack:()=>[83023]},ssr:!1,loading:()=>(0,a.jsx)("div",{className:"min-h-[200px] w-full animate-pulse rounded-lg bg-muted/20"})}),_=i.Ik({title:i.Yj().min(2,{message:"Title must be at least 2 characters."}),description:i.Yj().min(10,{message:"Description must be at least 10 characters."}),dateRange:i.Ik({from:i.p6(),to:i.p6()}),useShortUrl:i.zM().default(!1)}),V=e=>e.toLowerCase().replace(/\s+/g,"-").replace(/-+/g,"-").replace(/[^a-z0-9-]/g,"").replace(/^-+|-+$/g,"");function T({siteId:e,giveaway:t}){let{orgId:r,isLoaded:i}=(0,c.d)(),N=(0,l.n_)(d.FH.giveaways.updateGiveaway),E=(0,l.n_)(d.FH.shortUrls.createShortUrl),$=(0,l.n_)(d.FH.giveaways.updateGiveawayShortUrl),k=(0,l.n_)(d.FH.shortUrls.deleteShortUrl),[B,M]=(0,R.useState)(!1),[z,H]=(0,R.useState)(""),[A,W]=(0,R.useState)(!1),[G,J]=(0,R.useState)(""),{isOpen:Y,onOpen:Z,onClose:q}=(0,f.j)(),[X,K]=(0,R.useState)(null),Q=(0,u.useRouter)(),{onOpen:ee}=(0,P.Z)(),et=(0,l.IT)(d.FH.shortUrls.getShortUrlByGiveawayId,t._id&&r&&i?{giveawayId:t._id}:"skip"),{siteSettings:er}=(0,D.O)(),ea=(0,l.IT)(d.FH.projects.getProjectBySiteId,e&&r&&i?{siteId:e}:"skip");(0,R.useEffect)(()=>{ea?.error&&n.toast.error(ea.error.message)},[ea?.error]),(0,R.useEffect)(()=>{if(ea?.error){if("NOT_FOUND"===ea.error.code){console.log("Error loading giveaway basic info:",ea.error.message),n.toast.error(ea.error.message),Q.push("/projects");return}n.toast.error(ea.error.message)}},[ea?.error,Q]),(0,R.useEffect)(()=>{et?.error&&(0,F.Z4)(et,{NOT_FOUND:void 0}).hasError&&"NOT_FOUND"!==et.error.code&&n.toast.error(et.error.message),t.useShortUrl&&et?.data&&(eo.setValue("useShortUrl",!0),H(et.data.shortId))},[t.useShortUrl,et]);let es=(0,l.IT)(d.FH.shortUrls.checkAliasAvailability,z&&r&&i?{shortId:z}:"skip");(0,R.useEffect)(()=>{(async()=>{ea&&ea.data?.subdomain&&K(ea.data?.subdomain)})()},[e,ea]);let eo=(0,o.mN)({resolver:(0,s.u)(_),defaultValues:{title:t.title,description:t.description,dateRange:{from:t.startDate?new Date(t.startDate):new Date,to:new Date(t.endDate?t.endDate:Date.now()+6048e5)},useShortUrl:!1}}),ei=e=>(0,m._U)(e.toISOString().split("T")[0]),en=e=>new Date(e.toString()),el=()=>X?`https://${X}.virallaunch.ai/giveaway/${t._id}`:"",ed=(0,R.useMemo)(()=>V(z),[z]),ec=()=>et?.data?`https://virallaunch.ai/s/${et.data.shortId}`:`https://virallaunch.ai/s/${ed}`,eu=async e=>{try{await navigator.clipboard.writeText(e),M(!0),setTimeout(()=>M(!1),2e3)}catch(e){console.error("Failed to copy text: ",e)}},em=async()=>{if(et?.data)try{let r=await $({id:t._id,useShortUrl:!1,shortUrlId:void 0});if(r?.error){n.toast.error(r.error.message),eo.setValue("useShortUrl",!0);return}if(r.data?.success){eo.setValue("useShortUrl",!1),H("");let t=await k({shortUrlId:et.data._id,siteId:e});t.data?.success?n.toast.success("Short URL removed successfully"):t.error&&(n.toast.error("Failed to remove short URL"),eo.setValue("useShortUrl",!0))}else n.toast.error("Failed to update short URL settings"),eo.setValue("useShortUrl",!0)}catch(t){let e=t?.message||"Failed to update short URL settings";n.toast.error(e),console.error("Error updating short URL settings:",t),eo.setValue("useShortUrl",!0)}},eh=async e=>{e?(el()&&H((()=>{try{if(er?.siteWebURL){let e=er?.siteWebURL?.startsWith("http")?er?.siteWebURL:`https://${er?.siteWebURL}`,t=new URL(e).hostname.replace(/^www\./,"").replace(/\.(com|org|net|io|ai|dev|app|co|me|xyz|site)$/,""),r=t.split(".");t=r.length>1?r[0]:t;let a=V(t),s=(0,C.d_)("1234567890abcdef",3)();return`${a}-${s}`}return""}catch(e){return console.error("Error generating suggested alias:",e),""}})()),Z()):!e&&et?.data&&ee("short URL",em)},ef=async()=>{try{if(et?.data)return void n.toast.error("A short URL already exists for this giveaway");let r=V(z),a=r.length<3?"Alias must be at least 3 characters":r.length>30?"Alias cannot be longer than 30 characters":/^[a-z0-9-]+$/.test(r)?/--/.test(r)?"Consecutive hyphens are not allowed":/^-|-$/.test(r)?"Alias cannot start or end with a hyphen":null:"Only lowercase letters, numbers, and hyphens are allowed";if(a)return void n.toast.error(a);let s=await E({originalPath:`/giveaway/${t._id}`,domain:`${X}.virallaunch.ai`,type:"giveaway",giveawayId:t._id,siteId:e,customShortId:r});if(s.error||!s.data)return void n.toast.error(s.error?.message||"Failed to create short URL");
1let o=await $({id:t._id,useShortUrl:!0,shortUrlId:s.data.shortUrl});if(o?.error)return void n.toast.error(o.error.message);o.data?.success?(n.toast.success("Short URL created successfully"),eo.setValue("useShortUrl",!0),H(""),q()):(s.data.shortUrl&&await k({shortUrlId:s.data.shortUrl,siteId:e}),n.toast.error(o?.error?.message||"Failed to update giveaway settings"),eo.setValue("useShortUrl",!1))}catch(t){let e=t?.message||"Failed to create short URL";n.toast.error(e),console.error("Error creating short URL:",t),eo.setValue("useShortUrl",!1)}},ep=()=>{q(),H(""),J(""),et||eo.setValue("useShortUrl",!1)},ex=async e=>{W(!0),J("");try{if(!e)return void J("");if(es?.error)return void J(es.error.message);es?.data&&!es.data.isAvailable&&J("This alias is already taken")}catch(e){J("Error checking alias availability"),console.error("Error checking alias:",e)}finally{W(!1)}};if(!r||!i)return(0,a.jsxs)("div",{className:"flex h-[400px] items-center justify-center gap-2",children:[(0,a.jsx)(p.o,{size:"sm",color:"primary"}),(0,a.jsx)("p",{children:"Loading workspace..."})]});if(!X)return(0,a.jsxs)("div",{className:"flex h-[400px] flex-col items-center justify-center gap-2",children:[(0,a.jsx)("p",{className:"text-lg text-default-700",children:"Onboarding incomplete..."}),(0,a.jsx)("p",{className:"text-sm text-default-500",children:"Please set up the subdomain for your project before continuing."}),(0,a.jsx)(x.T,{variant:"solid",onPress:()=>Q.push("/onboarding"),className:"mt-4",children:"Complete Onboarding"})]});async function ey(e){try{await N({id:t._id,title:e.title,description:e.description,startDate:e.dateRange.from.toISOString(),endDate:e.dateRange.to.toISOString()}),n.toast.success("Basic information updated successfully.")}catch(e){console.error("Error submitting form:",e),n.toast.error("Failed to save basic information.")}}return(0,a.jsxs)(h.P.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3},"data-sentry-element":"motion.div","data-sentry-component":"GiveawayBasicInfo","data-sentry-source-file":"basic-info.tsx",children:[(0,a.jsx)(I.lV,{...eo,"data-sentry-element":"Form","data-sentry-source-file":"basic-info.tsx",children:(0,a.jsxs)("form",{onSubmit:eo.handleSubmit(ey),className:"space-y-8",children:[(0,a.jsxs)("div",{className:"space-y-2 pb-8",children:[(0,a.jsx)("h3",{className:"text-lg font-semibold",children:"Basic Information"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Set up the core details of your giveaway."})]}),(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsx)(y.r,{label:"Giveaway Title",placeholder:"Enter giveaway title...",value:eo.watch("title"),onChange:e=>eo.setValue("title",e.target.value),variant:"flat",labelPlacement:"outside",errorMessage:eo.formState.errors.title?.message,description:"This will be displayed as the main title of your giveaway.",classNames:{label:"text-default-700",description:"text-default-500"},"data-sentry-element":"Input","data-sentry-source-file":"basic-info.tsx"}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsxs)("div",{className:"flex items-center justify-between",children:[(0,a.jsx)("h4",{className:"text-sm text-default-700 ",children:"Giveaway URL"}),(0,a.jsx)(g.Z,{size:"sm",isSelected:eo.watch("useShortUrl"),onValueChange:eh,"data-sentry-element":"Switch","data-sentry-source-file":"basic-info.tsx",children:(0,a.jsx)("span",{className:"text-sm text-default-700",children:"Use Short URL"})})]}),(0,a.jsx)(y.r,{type:"text",value:eo.watch("useShortUrl")?ec():el(),readOnly:!0,variant:"flat",labelPlacement:"outside",description:"This is the URL that will be used to access your giveaway.",classNames:{label:"text-default-700",description:"text-default-500",input:"text-sm",inputWrapper:"bg-default-100 hover:!bg-default-100 hover:!opacity-100"},endContent:(0,a.jsx)(x.T,{variant:"light",className:"bg-transparent",size:"sm",isIconOnly:!0,onClick:()=>{eu(eo.watch("useShortUrl")?ec():el()),n.toast.success("URL copied to clipboard!")},children:(0,a.jsx)(L.A,{className:"h-4 w-4"})}),"data-sentry-element":"Input","data-sentry-source-file":"basic-info.tsx"})]})]}),(0,a.jsx)(I.zB,{control:eo.control,name:"description",render:({field:e})=>(0,a.jsxs)(I.eI,{children:[(0,a.jsx)(I.lR,{children:"Description"}),(0,a.jsx)(I.MJ,{children:(0,a.jsx)(O,{defaultContentHtml:t.description||void 0,defaultContent:{type:"doc",content:[]}
1,onUpdate:({editor:t})=>{e.onChange(t.getHTML())},className:"min-h-[200px]",disableLocalStorage:!0,compact:!0})}),(0,a.jsx)(I.Rr,{children:"Describe your giveaway and what participants can win."}),(0,a.jsx)(I.C5,{})]}),"data-sentry-element":"FormField","data-sentry-source-file":"basic-info.tsx"}),(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsx)("label",{className:"text-sm font-medium text-default-700",children:"Duration"}),(0,a.jsx)(S.o,{value:{start:ei(eo.watch("dateRange.from")),end:ei(eo.watch("dateRange.to"))},onChange:e=>{e?.start&&e?.end&&eo.setValue("dateRange",{from:en(e.start),to:en(e.end)})},className:"w-full","data-sentry-element":"DateRangePicker","data-sentry-source-file":"basic-info.tsx"}),(0,a.jsx)("p",{className:"text-sm text-default-500",children:"Select when your giveaway starts and ends."})]}),(0,a.jsx)("div",{className:"flex justify-end pt-4",children:(0,a.jsx)(x.T,{color:"primary",type:"submit",isLoading:eo.formState.isSubmitting,"data-sentry-element":"Button","data-sentry-source-file":"basic-info.tsx",children:"Update Basic Info"})})]})}),(0,a.jsx)(v.Y,{isOpen:Y,onClose:ep,"data-sentry-element":"Modal","data-sentry-source-file":"basic-info.tsx",children:(0,a.jsxs)(j.g,{"data-sentry-element":"ModalContent","data-sentry-source-file":"basic-info.tsx",children:[(0,a.jsx)(b.c,{"data-sentry-element":"ModalHeader","data-sentry-source-file":"basic-info.tsx",children:"Create Short URL"}),(0,a.jsx)(w.h,{"data-sentry-element":"ModalBody","data-sentry-source-file":"basic-info.tsx",children:(0,a.jsx)("div",{className:"space-y-4",children:(0,a.jsx)(y.r,{label:"Custom Alias",placeholder:"Enter your preferred alias",value:z,onChange:e=>{var t;let r;return r=V(t=e.target.value),void(H(t),ex(r))},description:(0,a.jsxs)("div",{className:"space-y-2",children:[(0,a.jsxs)("p",{children:["Your short URL will be: ",ec()]}),z&&ed!==z&&(0,a.jsxs)("p",{className:"text-sm text-default-500",children:["Will be saved as: ",ed]}),(0,a.jsxs)("ul",{className:"list-disc space-y-1 pl-4 text-xs text-default-500",children:[(0,a.jsxs)("li",{children:["Use ",3,"-",30," characters"]}),(0,a.jsx)("li",{children:"Only lowercase letters, numbers, and hyphens allowed"}),(0,a.jsx)("li",{children:"Spaces will be converted to hyphens"}),(0,a.jsx)("li",{children:"Special characters will be removed"})]})]}),errorMessage:G,startContent:A&&(0,a.jsx)(p.o,{size:"sm"}),"data-sentry-element":"Input","data-sentry-source-file":"basic-info.tsx"})})}),(0,a.jsxs)(U.q,{"data-sentry-element":"ModalFooter","data-sentry-source-file":"basic-info.tsx",children:[(0,a.jsx)(x.T,{variant:"bordered",onPress:ep,"data-sentry-element":"Button","data-sentry-source-file":"basic-info.tsx",children:"Cancel"}),(0,a.jsx)(x.T,{color:"primary",onPress:ef,isDisabled:!ed||!!G||A,"data-sentry-element":"Button","data-sentry-source-file":"basic-info.tsx",children:"Create Short URL"})]})]})})]})}},11444:(e,t,r)=>{r.d(t,{C5:()=>g,MJ:()=>x,Rr:()=>y,eI:()=>f,lR:()=>p,lV:()=>d,zB:()=>u});var a=r(45185),s=r(88581),o=r(95732),i=r(6582),n=r(57058),l=r(80900);let d=i.Op,c=s.createContext({}),u=({...e})=>(0,a.jsx)(c.Provider,{value:{name:e.name},"data-sentry-element":"FormFieldContext.Provider","data-sentry-component":"FormField","data-sentry-source-file":"form.tsx",children:(0,a.jsx)(i.xI,{...e,"data-sentry-element":"Controller","data-sentry-source-file":"form.tsx"})}),m=()=>{let e=s.useContext(c),t=s.useContext(h),{getFieldState:r,formState:a}=(0,i.xW)(),o=r(e.name,a);if(!e)throw Error("useFormField should be used within <FormField>");let{id:n}=t;return{id:n,name:e.name,formItemId:`${n}-form-item`,formDescriptionId:`${n}-form-item-description`,formMessageId:`${n}-form-item-message`,...o}},h=s.createContext({}),f=s.forwardRef(({className:e,...t},r)=>{let o=s.useId();return(0,a.jsx)(h.Provider,{value:{id:o},children:(0,a.jsx)("div",{ref:r,className:(0,n.cn)("space-y-2",e),...t})})});f.displayName="FormItem";let p=s.forwardRef(({className:e,...t},r)=>{let{error:s,formItemId:o}=m();return(0,a.jsx)(l.J,{ref:r,className:(0,n.cn)(s&&"text-destructive",e),htmlFor:o,...t})});p.displayName="FormLabel";let x=s.forwardRef(({...e},t)=>{let{error:r,formItemId:s,formDescriptionId:i,formMessageId:n}=m();return(0,a.jsx)(o.DX,{ref:t,id:s,"aria-describedby":r?`${i} ${n}`:`${i}`,"aria-invalid":!!r,...e})});x.displayName="FormControl";let y=s.forwardRef(({className:e,...t},r)=>{let{formDescriptionId:s}=m();return(0,a.jsx)("p",{ref:r,id:s,className:(0,n.cn)("text-[0.8rem] text-muted-foreground",e),...t})});y.displayName="FormDescription";let g=s.forwardRef(({className:e,children:t,...r},s)=>{let{error:o,formMessageId:i}=m(),l=o?String(o?.message):t;return l?(0,a.jsx)("p",{ref:s,id:i,className:(0,n.cn)("text-[0.8rem] font-medium text-destructive",e),...r,children:l}):null});g.displayName="FormMessage"},29636:(e,t,r)=>{r.d(t,{Z:()=>a});let a=(0,r(20495).v)(e=>({isOpen:!1,isLoading:!1,item:void 0,onDelete:void 0,onOpen:(t,r)=>e({isOpen:!0,item:t,onDelete:r,isLoading:!1}),onClose:()=>e({isOpen:!1,item:void 0,onDelete:void 0,isLoading:!1}),setIsLoading:t=>e({isLoading:t})}))},40447:(e,t,r)=>{r.d(t,{I:()=>o});var a=r(20495);let s={siteId:null,projectData:void 0,personas:void 0,customBrandVoices:void 0,siteSettings:void 0,isLoading:!1,error:void 0},o=(0,a.v)(e=>({...s,setSiteId:t=>e({siteId:t}),setProjectData:t=>e({projectData:t}),setPersonas:t=>e({personas:t}),setCustomBrandVoices:t=>e({customBrandVoices:t}),setSiteSettings:t=>e({siteSettings:t}),setIsLoading:t=>e({isLoading:t}),setError:t=>e({error:t}),reset:()=>e(s)}))},54708:(e,t,r)=>{r.d(t,{O:()=>l,ProjectContextProvider:()=>n});var a=r(45185),s=r(88581),o=r(40447);let i=(0,s.createContext)(void 0);function n({children:e}){let t=(0,o.I)();return(0,a.jsx)(i.Provider,{value:{siteId:t.siteId,projectData:t.projectData,personas:t.personas,customBrandVoices:t.customBrandVoices,siteSettings:t.siteSettings,isLoading:t.isLoading,error:t.error},"data-sentry-element":"ProjectContext.Provider","data-sentry-component":"ProjectContextProvider","data-sentry-source-file":"project-context-provider.tsx",children:e})}function l(){let e=(0,s.useContext)(i);if(void 0===e)throw Error("useProjectContext must be used within a ProjectContextProvider");return e}},80900:(e,t,r)=>{r.d(t,{J:()=>d});var a=r(45185),s=r(88581),o=r(14735),i=r(28281),n=r(57058);let l=(0,i.F)("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),d=s.forwardRef(({className:e,...t},r)=>(0,a.jsx)(o.b,{ref:r,className:(0,n.cn)(l(),e),...t}));d.displayName=o.b.displayName}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.