-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
127 changed files
with
912 additions
and
122 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
apps/member-profile/app/routes/_profile.resources.$id_.delete.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { | ||
type ActionFunctionArgs, | ||
json, | ||
type LoaderFunctionArgs, | ||
redirect, | ||
} from '@remix-run/node'; | ||
import { | ||
Form, | ||
useActionData, | ||
useLoaderData, | ||
useSearchParams, | ||
} from '@remix-run/react'; | ||
|
||
import { deleteResource } from '@oyster/core/resources/server'; | ||
import { db } from '@oyster/db'; | ||
import { Button, ErrorMessage, getErrors, Modal } from '@oyster/ui'; | ||
|
||
import { Route } from '@/shared/constants'; | ||
import { | ||
commitSession, | ||
ensureUserAuthenticated, | ||
toast, | ||
user, | ||
} from '@/shared/session.server'; | ||
|
||
export async function loader({ params, request }: LoaderFunctionArgs) { | ||
const session = await ensureUserAuthenticated(request); | ||
|
||
const resource = await db | ||
.selectFrom('resources') | ||
.select(['title']) | ||
.where('id', '=', params.id as string) | ||
.where('postedBy', '=', user(session)) | ||
.executeTakeFirst(); | ||
|
||
if (!resource) { | ||
throw new Response(null, { | ||
status: 404, | ||
statusText: 'The resource you are looking for does not exist.', | ||
}); | ||
} | ||
|
||
return json(resource); | ||
} | ||
|
||
export async function action({ params, request }: ActionFunctionArgs) { | ||
const session = await ensureUserAuthenticated(request); | ||
|
||
await deleteResource(params.id as string); | ||
|
||
toast(session, { | ||
message: 'Resource deleted successfully.', | ||
}); | ||
|
||
const url = new URL(request.url); | ||
|
||
url.pathname = Route['/resources']; | ||
|
||
return redirect(url.toString(), { | ||
headers: { | ||
'Set-Cookie': await commitSession(session), | ||
}, | ||
}); | ||
} | ||
|
||
export default function DeleteResourceModal() { | ||
const { title } = useLoaderData<typeof loader>(); | ||
const { error } = getErrors(useActionData<typeof action>()); | ||
const [searchParams] = useSearchParams(); | ||
|
||
return ( | ||
<Modal | ||
onCloseTo={{ | ||
pathname: Route['/resources'], | ||
search: searchParams.toString(), | ||
}} | ||
> | ||
<Modal.Header> | ||
<Modal.Title>Delete Resource</Modal.Title> | ||
<Modal.CloseButton /> | ||
</Modal.Header> | ||
|
||
<Modal.Description> | ||
Are you sure you want to delete "{title}"? This action cannot be undone. | ||
</Modal.Description> | ||
|
||
<Form className="form" method="post"> | ||
<ErrorMessage>{error}</ErrorMessage> | ||
|
||
<Button.Group> | ||
<Button.Submit color="error">Delete</Button.Submit> | ||
</Button.Group> | ||
</Form> | ||
</Modal> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
export { getGoogleAuthUri } from './modules/authentication/shared/oauth.utils'; | ||
export { sendOneTimeCode } from './modules/authentication/use-cases/send-one-time-code'; | ||
export { verifyOneTimeCode } from './modules/authentication/use-cases/verify-one-time-code'; | ||
export { getEvent } from './modules/event/queries/get-event'; | ||
export { listEvents } from './modules/event/queries/list-events'; | ||
export { addEventRecordingLink } from './modules/event/use-cases/add-event-recording-link'; | ||
export { createEvent } from './modules/event/use-cases/create-event'; | ||
export { getFeatureFlag } from './modules/feature-flag/queries/get-feature-flag'; | ||
export { listFeatureFlags } from './modules/feature-flag/queries/list-feature-flags'; | ||
export { createFeatureFlag } from './modules/feature-flag/use-cases/create-feature-flag'; | ||
export { deleteFeatureFlag } from './modules/feature-flag/use-cases/delete-feature-flag'; | ||
export { editFeatureFlag } from './modules/feature-flag/use-cases/edit-feature-flag'; | ||
export { addIcebreakerPrompt } from './modules/icebreaker/use-cases/add-icebreaker-prompt'; | ||
export { activateMember } from './modules/member/use-cases/activate-member'; | ||
export { updateMemberEmail } from './modules/member/use-cases/update-member-email'; | ||
export { addOnboardingSessionAttendees } from './modules/onboarding-session/use-cases/add-onboarding-session-attendees'; | ||
export { uploadOnboardingSession } from './modules/onboarding-session/use-cases/upload-onboarding-session'; | ||
export { getEvent } from './modules/events/queries/get-event'; | ||
export { listEvents } from './modules/events/queries/list-events'; | ||
export { addEventRecordingLink } from './modules/events/use-cases/add-event-recording-link'; | ||
export { createEvent } from './modules/events/use-cases/create-event'; | ||
export { getFeatureFlag } from './modules/feature-flags/queries/get-feature-flag'; | ||
export { listFeatureFlags } from './modules/feature-flags/queries/list-feature-flags'; | ||
export { createFeatureFlag } from './modules/feature-flags/use-cases/create-feature-flag'; | ||
export { deleteFeatureFlag } from './modules/feature-flags/use-cases/delete-feature-flag'; | ||
export { editFeatureFlag } from './modules/feature-flags/use-cases/edit-feature-flag'; | ||
export { addIcebreakerPrompt } from './modules/icebreakers/use-cases/add-icebreaker-prompt'; | ||
export { activateMember } from './modules/members/use-cases/activate-member'; | ||
export { updateMemberEmail } from './modules/members/use-cases/update-member-email'; | ||
export { addOnboardingSessionAttendees } from './modules/onboarding-sessions/use-cases/add-onboarding-session-attendees'; | ||
export { uploadOnboardingSession } from './modules/onboarding-sessions/use-cases/upload-onboarding-session'; | ||
export { parseCsv } from './shared/utils/csv'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.