Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/appConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ export const URL_END_POINT = {
GET_LAST_ACTIVE_GAME: 'APIs/GetLastActiveGame.php',
SYNC_METAFY_SUBSCRIBERS: 'APIs/SyncMetafySubscribers.php',
GET_APP_INFO: 'AccountFiles/GetAppInfoAPI.php',
GENERATE_AUTH_TOKEN: 'AccountFiles/GenerateAuthTokenAPI.php'
GENERATE_AUTH_TOKEN: 'AccountFiles/GenerateAuthTokenAPI.php',
MATCH_RESULT_WEBHOOK: 'APIs/MatchResultWebhookAPI.php'
};

export const GAME_VISIBILITY = {
Expand Down
18 changes: 18 additions & 0 deletions src/features/api/apiSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ import {
UpdateFavoriteDeckRequest,
UpdateFavoriteDeckResponse
} from 'interface/API/UpdateFavoriteDeck.php';
import {
MatchResultWebhookRequest,
MatchResultWebhookResponse
} from 'interface/API/MatchResultWebhookAPI.php';
import { PatreonLoginResponse } from 'routes/user/profile/linkpatreon/linkPatreon';
import { UserProfileAPIResponse } from 'interface/API/UserProfileAPI.php';
import {
Expand Down Expand Up @@ -449,6 +453,19 @@ export const apiSlice = createApi({
};
}
}),
setMatchResultWebhook: builder.mutation<
MatchResultWebhookResponse,
MatchResultWebhookRequest
>({
query: (body: MatchResultWebhookRequest) => {
return {
url: URL_END_POINT.MATCH_RESULT_WEBHOOK,
method: 'POST',
body: body,
responseHandler: parseResponse
};
}
}),
deleteAccount: builder.mutation<
DeleteAccountAPIResponse,
DeleteAccountAPIRequest
Expand Down Expand Up @@ -1113,6 +1130,7 @@ export const {
useDeleteDeckMutation,
useAddFavoriteDeckMutation,
useUpdateFavoriteDeckMutation,
useSetMatchResultWebhookMutation,
useDeleteAccountMutation,
useLoginMutation,
useLoginWithCookieQuery,
Expand Down
8 changes: 8 additions & 0 deletions src/interface/API/MatchResultWebhookAPI.php.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export interface MatchResultWebhookRequest {
webhookUrl: string;
}

export interface MatchResultWebhookResponse {
success: boolean;
message: string;
}
1 change: 1 addition & 0 deletions src/interface/API/UserProfileAPI.php.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface UserProfileAPIResponse {
isMetafyLinked?: boolean;
isMetafySupporter?: boolean;
metafyCommunities?: MetafyCommunity[];
matchResultWebhookUrl?: string;
}
60 changes: 59 additions & 1 deletion src/routes/user/profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
useGetFavoriteDecksQuery,
useGetUserProfileQuery,
useAddFavoriteDeckMutation,
useUpdateFavoriteDeckMutation
useUpdateFavoriteDeckMutation,
useSetMatchResultWebhookMutation
} from 'features/api/apiSlice';
import { DeleteDeckAPIResponse } from 'interface/API/DeleteDeckAPI.php';
import { DeleteAccountAPIResponse } from 'interface/API/DeleteAccountAPI.php';
Expand Down Expand Up @@ -56,6 +57,15 @@ export const ProfilePage = () => {
const [addFavoriteDeck] = useAddFavoriteDeckMutation();
const [updateFavoriteDeck] = useUpdateFavoriteDeckMutation();
const [deleteAccount, { isLoading: isDeleting }] = useDeleteAccountMutation();
const [webhookInput, setWebhookInput] = useState('');
const [isSavingWebhook, setIsSavingWebhook] = useState(false);
const [setMatchResultWebhook] = useSetMatchResultWebhookMutation();

useEffect(() => {
if (profileData?.matchResultWebhookUrl !== undefined) {
setWebhookInput(profileData.matchResultWebhookUrl ?? '');
}
}, [profileData?.matchResultWebhookUrl]);

const handleDeleteDeckMessage = (resp: DeleteDeckAPIResponse): string => {
if (resp.message === 'Deck deleted successfully.') {
Expand All @@ -65,6 +75,26 @@ export const ProfilePage = () => {
}
};

const handleSaveWebhook = async () => {
setIsSavingWebhook(true);
try {
const resp = await setMatchResultWebhook({
webhookUrl: webhookInput.trim()
}).unwrap();
if (resp.success) {
toast.success(resp.message, { position: 'top-center' });
} else {
toast.error(resp.message, { position: 'top-center' });
}
} catch {
toast.error('Failed to save webhook. Please try again.', {
position: 'top-center'
});
} finally {
setIsSavingWebhook(false);
}
};

const handleDeleteDeck = async (deckLink: string) => {
try {
const deleteDeckPromise = deleteDeck({ deckLink }).unwrap();
Expand Down Expand Up @@ -347,6 +377,34 @@ export const ProfilePage = () => {
)}
</div>
)}

{/* Match Result Webhook */}
{!profileIsLoading && (
<div className={styles.webhookSection}>
<h3>Match Result Webhook</h3>
<p>
Receive your match results at a custom URL after each
game. Must be a public https:// address.
</p>
<div className={styles.webhookInputRow}>
<input
type="url"
placeholder="https://your-webhook.example.com/results"
value={webhookInput}
onChange={(e) => setWebhookInput(e.target.value)}
disabled={isSavingWebhook}
className={styles.addDeckInput}
/>
<button
className={styles.addDeckButton}
onClick={handleSaveWebhook}
disabled={isSavingWebhook}
>
{isSavingWebhook ? 'Saving...' : 'Save'}
</button>
</div>
</div>
)}
</div>

<FriendsList className={styles.friendsSection} />
Expand Down
34 changes: 34 additions & 0 deletions src/routes/user/profile/profile.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,40 @@ td {
border-color: rgba(212, 175, 55, 0.5);
}

/* Match Result Webhook Section */
.webhookSection {
margin: 1rem 0;
padding: 1rem;
background: rgba(255, 255, 255, 0.03);
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.08);
}

.webhookSection h3 {
margin-top: 0;
margin-bottom: 0.5rem;
color: rgba(255, 255, 255, 0.9);
font-size: 1.3em;
}

.webhookSection p {
margin: 0 0 0.75rem;
color: rgba(255, 255, 255, 0.7);
font-size: 0.9em;
}

.webhookInputRow {
display: flex;
gap: 0.5rem;
align-items: stretch;
}

@media (max-width: 575px) {
.webhookInputRow {
flex-direction: column;
}
}

.metafyToggleButton {
padding: 0.5rem 1rem;
margin: 1rem 0;
Expand Down