15 lines
16 KiB
JavaScript
15 lines
16 KiB
JavaScript
|
|
var te=r=>{throw TypeError(r)};var A=(r,t,s)=>t.has(r)||te("Cannot "+s);var o=(r,t,s)=>(A(r,t,"read from private field"),s?s.call(r):t.get(r)),w=(r,t,s)=>t.has(r)?te("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(r):t.set(r,s),D=(r,t,s,a)=>(A(r,t,"write to private field"),a?a.call(r,s):t.set(r,s),s),C=(r,t,s)=>(A(r,t,"access private method"),s);import{o as me,a_ as Ce,a$ as Ee,b0 as ie,b1 as ke,b2 as ue,b3 as xe,r as u,b4 as Me,b5 as Se,$ as Ie,u as qe,a as _e,p as Le,a2 as Oe,j as e,L as I,x as z,y as R,v as m,B as re,q,X as ze,b6 as Re,A as Pe,ag as ae,ah as ne,C as Te,s as E,I as Ue,M as Ke,aR as oe,aY as B,w as k,z as Q}from"./index-oAPVDf-r.js";import{B as P}from"./badge-Qwi4CUXx.js";import{u as Fe}from"./useMissionExamples-B0el-PHm.js";import{u as Ae}from"./useQuery-BxfmyRLz.js";import{C as Be}from"./circle-alert-C1Hs9zwh.js";import{A as Qe}from"./arrow-left-m6EiMbb-.js";import{S as $e}from"./save-BwjzM02b.js";import{E as He}from"./eye-G89nJUb2.js";import{I as $}from"./image-DuU1QaV8.js";import{T as Ve}from"./trending-up-Be0ZnpBQ.js";import{C as We}from"./clock-DRtqJZUo.js";import{U as Xe}from"./upload-LLBu8Q_P.js";import{T as le}from"./trash-2-A3LTadZ7.js";/**
|
||
|
|
* @license lucide-react v0.462.0 - ISC
|
||
|
|
*
|
||
|
|
* This source code is licensed under the ISC license.
|
||
|
|
* See the LICENSE file in the root directory of this source tree.
|
||
|
|
*/const Ye=me("Minus",[["path",{d:"M5 12h14",key:"1ays0h"}]]);/**
|
||
|
|
* @license lucide-react v0.462.0 - ISC
|
||
|
|
*
|
||
|
|
* This source code is licensed under the ISC license.
|
||
|
|
* See the LICENSE file in the root directory of this source tree.
|
||
|
|
*/const Ge=me("Pen",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]]);var N,b,c,p,g,T,H,de,Je=(de=class extends Ce{constructor(t,s){super();w(this,g);w(this,N);w(this,b);w(this,c);w(this,p);D(this,N,t),this.setOptions(s),this.bindMethods(),C(this,g,T).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var a;const s=this.options;this.options=o(this,N).defaultMutationOptions(t),Ee(this.options,s)||o(this,N).getMutationCache().notify({type:"observerOptionsUpdated",mutation:o(this,c),observer:this}),s!=null&&s.mutationKey&&this.options.mutationKey&&ie(s.mutationKey)!==ie(this.options.mutationKey)?this.reset():((a=o(this,c))==null?void 0:a.state.status)==="pending"&&o(this,c).setOptions(this.options)}onUnsubscribe(){var t;this.hasListeners()||(t=o(this,c))==null||t.removeObserver(this)}onMutationUpdate(t){C(this,g,T).call(this),C(this,g,H).call(this,t)}getCurrentResult(){return o(this,b)}reset(){var t;(t=o(this,c))==null||t.removeObserver(this),D(this,c,void 0),C(this,g,T).call(this),C(this,g,H).call(this)}mutate(t,s){var a;return D(this,p,s),(a=o(this,c))==null||a.removeObserver(this),D(this,c,o(this,N).getMutationCache().build(o(this,N),this.options)),o(this,c).addObserver(this),o(this,c).execute(t)}},N=new WeakMap,b=new WeakMap,c=new WeakMap,p=new WeakMap,g=new WeakSet,T=function(){var s;const t=((s=o(this,c))==null?void 0:s.state)??ke();D(this,b,{...t,isPending:t.status==="pending",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset})},H=function(t){ue.batch(()=>{var s,a,d,n,j,y,_,L;if(o(this,p)&&this.hasListeners()){const f=o(this,b).variables,x=o(this,b).context;(t==null?void 0:t.type)==="success"?((a=(s=o(this,p)).onSuccess)==null||a.call(s,t.data,f,x),(n=(d=o(this,p)).onSettled)==null||n.call(d,t.data,null,f,x)):(t==null?void 0:t.type)==="error"&&((y=(j=o(this,p)).onError)==null||y.call(j,t.error,f,x),(L=(_=o(this,p)).onSettled)==null||L.call(_,void 0,t.error,f,x))}this.listeners.forEach(f=>{f(o(this,b))})})},de);function ce(r,t){const s=xe(),[a]=u.useState(()=>new Je(s,r));u.useEffect(()=>{a.setOptions(r)},[a,r]);const d=u.useSyncExternalStore(u.useCallback(j=>a.subscribe(ue.batchCalls(j)),[a]),()=>a.getCurrentResult(),()=>a.getCurrentResult()),n=u.useCallback((j,y)=>{a.mutate(j,y).catch(Me)},[a]);if(d.error&&Se(a.options.throwOnError,[d.error]))throw d.error;return{...d,mutate:n,mutateAsync:d.mutate}}const xs=()=>{const{id:r}=Ie(),t=qe(),{t:s}=_e(),{user:a}=Le(),d=xe(),{mission:n,loading:j,error:y}=Oe(r),{goodExamples:_,badExamples:L,hasExamples:f,uploading:x,uploadExample:he,deleteExample:pe}=Fe(r),[h,U]=u.useState(!1),[V,W]=u.useState(""),[X,Y]=u.useState(""),[G,J]=u.useState(""),[M,Z]=u.useState(0),v=u.useRef(null),ee=async i=>{var S;const l=(S=i.target.files)==null?void 0:S[0];if(l){if(!l.type.startsWith("image/")){k.error(s("orderer.missionDetail.onlyImagesAllowed"));return}if(l.size>5*1024*1024){k.error(s("orderer.missionDetail.maxFileSize"));return}await he(l),v.current&&(v.current.value="")}},ge=async(i,l)=>{confirm(s("orderer.missionDetail.confirmDeleteImage"))&&await pe(i,l)},{data:O=[],isLoading:je}=Ae({queryKey:["mission-claims",r],queryFn:async()=>{if(!r)return[];const{data:i,error:l}=await Q.from("claims").select(`
|
||
|
|
*,
|
||
|
|
submissions (*)
|
||
|
|
`).eq("mission_id",r).order("created_at",{ascending:!1});if(l)throw l;return i||[]},enabled:!!r}),fe=O.length,Ne=O.filter(i=>i.status==="pending"),be=O.filter(i=>i.status==="approved"),ve=O.reduce((i,l)=>{var S;return i+(((S=l.submissions)==null?void 0:S.length)||0)},0),K=ce({mutationFn:async i=>{if(!r)throw new Error("Mission ID missing");const{error:l}=await Q.from("missions").update(i).eq("id",r);if(l)throw l},onSuccess:()=>{k.success(s("orderer.missionDetail.missionUpdated")),d.invalidateQueries({queryKey:["mission",r]}),d.invalidateQueries({queryKey:["orderer-missions"]}),U(!1)},onError:i=>{k.error(s("orderer.missionDetail.couldNotUpdate")+": "+i.message)}}),F=ce({mutationFn:async()=>{if(!r)throw new Error("Mission ID missing");const{error:i}=await Q.from("missions").update({status:"cancelled"}).eq("id",r);if(i)throw i},onSuccess:()=>{k.success(s("orderer.missionDetail.missionCancelled")),d.invalidateQueries({queryKey:["mission",r]}),d.invalidateQueries({queryKey:["orderer-missions"]})},onError:i=>{k.error(s("orderer.missionDetail.couldNotCancel")+": "+i.message)}}),ye=()=>{n&&(W(n.title),Y(n.description||""),J(n.instructions||""),Z(n.reward_credits),U(!0))},we=()=>{K.mutate({title:V,description:X,instructions:G,reward_credits:M})},se=i=>{const l=Math.max(1,M+i);Z(l)};if(j||je)return e.jsx("div",{className:"min-h-screen bg-background flex items-center justify-center",children:e.jsx(I,{className:"w-8 h-8 animate-spin text-primary"})});if(y||!n)return e.jsxs("div",{className:"min-h-screen bg-background text-foreground pb-24",children:[e.jsx("main",{className:"p-4 pt-6",children:e.jsx(z,{className:"glass-card border-destructive/30",children:e.jsxs(R,{className:"p-6 text-center",children:[e.jsx(Be,{className:"w-12 h-12 mx-auto text-destructive mb-4"}),e.jsx("h2",{className:"text-xl font-bold mb-2",children:s("orderer.missionDetail.missionNotFound")}),e.jsx("p",{className:"text-muted-foreground mb-4",children:s("orderer.missionDetail.missionNotFoundDesc")}),e.jsx(m,{onClick:()=>t("/orderer/dashboard"),children:s("orderer.missionDetail.backToDashboard")})]})})}),e.jsx(re,{})]});if(n.created_by!==(a==null?void 0:a.id))return t(`/mission/${r}`),null;const De=i=>{switch(i){case"active":return e.jsx(P,{className:"bg-green-600 text-white",children:s("orderer.status.active")});case"completed":return e.jsx(P,{variant:"secondary",children:s("orderer.status.completed")});case"cancelled":return e.jsx(P,{variant:"destructive",children:s("orderer.status.cancelled")});default:return e.jsx(P,{variant:"outline",children:i})}};return e.jsxs("div",{className:"min-h-screen bg-background text-foreground pb-24",children:[e.jsxs("main",{className:"p-4 space-y-4 pt-6",children:[e.jsxs(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(m,{variant:"ghost",size:"icon",onClick:()=>t("/orderer/dashboard"),children:e.jsx(Qe,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg font-bold",children:s("orderer.missionDetail.title")}),e.jsx("p",{className:"text-xs text-muted-foreground",children:s("orderer.missionDetail.ordererView")})]})]}),h?e.jsxs("div",{className:"flex gap-2",children:[e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>U(!1),children:e.jsx(ze,{className:"w-4 h-4"})}),e.jsxs(m,{size:"sm",onClick:we,disabled:K.isPending,children:[K.isPending?e.jsx(I,{className:"w-4 h-4 animate-spin"}):e.jsx($e,{className:"w-4 h-4 mr-2"}),s("orderer.missionDetail.save")]})]}):e.jsxs(m,{variant:"outline",size:"sm",onClick:ye,children:[e.jsx(Ge,{className:"w-4 h-4 mr-2"}),s("orderer.missionDetail.edit")]})]}),e.jsx(q.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{delay:.05},children:e.jsx(z,{className:"glass-card",children:e.jsxs(R,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-4",children:[De(n.status),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[s("orderer.missionDetail.created")," ",new Date(n.created_at).toLocaleDateString(
|