@@ -46,7 +46,6 @@ interface Quote {
4646 createdAt : string ;
4747 workspace : { slackTeamName : string ; slug : string } ;
4848 channel : { channelName : string } ;
49- socialPost : { id : string } | null ;
5049}
5150
5251interface Pagination {
@@ -77,6 +76,8 @@ export function AdminQuotesManager() {
7776 const [ previewQuote , setPreviewQuote ] = useState < Quote | null > ( null ) ;
7877 const [ saving , setSaving ] = useState ( false ) ;
7978 const [ creatingPost , setCreatingPost ] = useState < string | null > ( null ) ;
79+ // Track quotes that had posts created this session (id → post id)
80+ const [ createdPosts , setCreatedPosts ] = useState < Record < string , string > > ( { } ) ;
8081 const searchTimer = useRef < ReturnType < typeof setTimeout > > ( null ) ;
8182
8283 useEffect ( ( ) => {
@@ -98,9 +99,15 @@ export function AdminQuotesManager() {
9899 if ( statusFilter ) params . set ( "status" , statusFilter ) ;
99100
100101 const res = await fetch ( `/api/admin/quotes?${ params } ` ) ;
102+ if ( ! res . ok ) {
103+ toast . error ( "Failed to load quotes" ) ;
104+ return ;
105+ }
101106 const data = await res . json ( ) ;
102- setQuotes ( data . quotes ) ;
107+ setQuotes ( data . quotes ?? [ ] ) ;
103108 setPagination ( data . pagination ) ;
109+ } catch {
110+ toast . error ( "Failed to load quotes" ) ;
104111 } finally {
105112 setLoading ( false ) ;
106113 }
@@ -136,7 +143,7 @@ export function AdminQuotesManager() {
136143 }
137144
138145 async function handleCreatePost ( quote : Quote ) {
139- if ( quote . socialPost ) {
146+ if ( createdPosts [ quote . id ] ) {
140147 router . push ( "/admin/posts" ) ;
141148 return ;
142149 }
@@ -150,17 +157,7 @@ export function AdminQuotesManager() {
150157 return ;
151158 }
152159 const data = await res . json ( ) ;
153- // Update local state so the button flips to "View Post"
154- setQuotes ( ( prev ) =>
155- prev . map ( ( q ) =>
156- q . id === quote . id ? { ...q , socialPost : { id : data . id } } : q ,
157- ) ,
158- ) ;
159- if ( previewQuote ?. id === quote . id ) {
160- setPreviewQuote ( ( prev ) =>
161- prev ? { ...prev , socialPost : { id : data . id } } : prev ,
162- ) ;
163- }
160+ setCreatedPosts ( ( prev ) => ( { ...prev , [ quote . id ] : data . id } ) ) ;
164161 toast . success ( data . existed ? "Post already exists" : "Post created" , {
165162 action : {
166163 label : "View Posts" ,
@@ -293,7 +290,7 @@ export function AdminQuotesManager() {
293290 { quote . status === "COMPLETED" && (
294291 < div className = "mt-3" onClick = { ( e ) => e . stopPropagation ( ) } >
295292 < Button
296- variant = { quote . socialPost ? "secondary" : "outline" }
293+ variant = { createdPosts [ quote . id ] ? "secondary" : "outline" }
297294 size = "sm"
298295 className = "w-full text-xs"
299296 disabled = { creatingPost === quote . id }
@@ -302,7 +299,7 @@ export function AdminQuotesManager() {
302299 < Send className = "mr-1.5 h-3 w-3" />
303300 { creatingPost === quote . id
304301 ? "Creating..."
305- : quote . socialPost
302+ : createdPosts [ quote . id ]
306303 ? "View Post"
307304 : "Create Post" }
308305 </ Button >
@@ -441,7 +438,7 @@ export function AdminQuotesManager() {
441438 < Send className = "mr-2 h-4 w-4" />
442439 { creatingPost === previewQuote . id
443440 ? "Creating..."
444- : previewQuote . socialPost
441+ : createdPosts [ previewQuote . id ]
445442 ? "View Post"
446443 : "Create Post" }
447444 </ Button >
0 commit comments