Update project submission

pull/6513/head
Kamran Ahmed 3 months ago
parent d0e76c85ce
commit 1b332af100
  1. 29
      src/components/Projects/SubmissionRequirement.tsx
  2. 48
      src/components/Projects/SubmitProjectModal.tsx

@ -1,14 +1,16 @@
import type { ReactNode } from 'react'; import type { ReactNode } from 'react';
import { cn } from '../../lib/classname.ts'; import { cn } from '../../lib/classname.ts';
import {CheckIcon, CircleDashed, X} from 'lucide-react'; import { CheckIcon, CircleDashed, Loader, Loader2, X } from 'lucide-react';
import { Spinner } from '../ReactIcons/Spinner.tsx';
type SubmissionRequirementProps = { type SubmissionRequirementProps = {
status: 'pending' | 'success' | 'error'; status: 'pending' | 'success' | 'error';
children: ReactNode; children: ReactNode;
isLoading?: boolean;
}; };
export function SubmissionRequirement(props: SubmissionRequirementProps) { export function SubmissionRequirement(props: SubmissionRequirementProps) {
const { status, children } = props; const { status, isLoading = false, children } = props;
return ( return (
<div <div
@ -18,12 +20,23 @@ export function SubmissionRequirement(props: SubmissionRequirementProps) {
'bg-red-200': status === 'error', 'bg-red-200': status === 'error',
})} })}
> >
{status === 'pending' ? ( {!isLoading && (
<CircleDashed className="h-4 w-4 text-gray-400" /> <>
) : status === 'success' ? ( {status === 'pending' ? (
<CheckIcon className="h-4 w-4 text-green-800" /> <CircleDashed className="h-4 w-4 text-gray-400" />
) : ( ) : status === 'success' ? (
<X className="h-4 w-4 text-yellow-800" /> <CheckIcon className="h-4 w-4 text-green-800" />
) : (
<X className="h-4 w-4 text-yellow-800" />
)}
</>
)}
{isLoading && (
<Loader2
className={'h-4 w-4 animate-spin text-gray-400'}
strokeWidth={3}
/>
)} )}
<span className="ml-2">{children}</span> <span className="ml-2">{children}</span>
</div> </div>

@ -1,10 +1,8 @@
import { CheckIcon, CircleDashed, CopyIcon, X } from 'lucide-react'; import { CheckIcon, CopyIcon, X } from 'lucide-react';
import { Modal } from '../Modal'; import { Modal } from '../Modal';
import { useState, type FormEvent, type ReactNode } from 'react'; import { type FormEvent, useState } from 'react';
import { useToast } from '../../hooks/use-toast';
import { httpPost } from '../../lib/http'; import { httpPost } from '../../lib/http';
import { GitHubIcon } from '../ReactIcons/GitHubIcon.tsx'; import { GitHubIcon } from '../ReactIcons/GitHubIcon.tsx';
import { cn } from '../../lib/classname.ts';
import { SubmissionRequirement } from './SubmissionRequirement.tsx'; import { SubmissionRequirement } from './SubmissionRequirement.tsx';
import { useCopyText } from '../../hooks/use-copy-text.ts'; import { useCopyText } from '../../hooks/use-copy-text.ts';
@ -165,6 +163,12 @@ export function SubmitProjectModal(props: SubmitProjectModalProps) {
throw new Error('Add the project page URL to the readme file'); throw new Error('Add the project page URL to the readme file');
} }
setVerificationChecks({
repositoryExists: 'success',
readmeExists: 'success',
projectUrlExists: 'success',
});
const submitProjectUrl = `${import.meta.env.PUBLIC_API_URL}/v1-submit-project/${projectId}`; const submitProjectUrl = `${import.meta.env.PUBLIC_API_URL}/v1-submit-project/${projectId}`;
const { response: submitResponse, error } = const { response: submitResponse, error } =
await httpPost<SubmitProjectResponse>(submitProjectUrl, { await httpPost<SubmitProjectResponse>(submitProjectUrl, {
@ -172,10 +176,12 @@ export function SubmitProjectModal(props: SubmitProjectModalProps) {
}); });
if (error || !submitResponse) { if (error || !submitResponse) {
throw new Error(error?.message || 'Failed to submit project'); throw new Error(
error?.message || 'Error submitting project. Please try again!',
);
} }
setSuccessMessage('Repository verified successfully'); setSuccessMessage('Solution submitted successfully!');
setIsLoading(false); setIsLoading(false);
onSubmit(submitResponse); onSubmit(submitResponse);
@ -196,13 +202,22 @@ export function SubmitProjectModal(props: SubmitProjectModalProps) {
</p> </p>
<div className="my-4 flex flex-col gap-1"> <div className="my-4 flex flex-col gap-1">
<SubmissionRequirement status={verificationChecks.repositoryExists}> <SubmissionRequirement
isLoading={isLoading}
status={verificationChecks.repositoryExists}
>
URL must point to a public GitHub repository URL must point to a public GitHub repository
</SubmissionRequirement> </SubmissionRequirement>
<SubmissionRequirement status={verificationChecks.readmeExists}> <SubmissionRequirement
isLoading={isLoading}
status={verificationChecks.readmeExists}
>
Repository must contain a README file Repository must contain a README file
</SubmissionRequirement> </SubmissionRequirement>
<SubmissionRequirement status={verificationChecks.projectUrlExists}> <SubmissionRequirement
isLoading={isLoading}
status={verificationChecks.projectUrlExists}
>
README file must contain the{' '} README file must contain the{' '}
<button <button
className={ className={
@ -243,6 +258,13 @@ export function SubmitProjectModal(props: SubmitProjectModalProps) {
onChange={(e) => setRepoUrl(e.target.value)} onChange={(e) => setRepoUrl(e.target.value)}
/> />
<button
type="submit"
className="mt-2 w-full rounded-lg bg-black p-2 font-medium text-white disabled:opacity-50"
disabled={isLoading}
>
{isLoading ? 'Verifying...' : 'Verify and Submit'}
</button>
{error && ( {error && (
<p className="mt-2 text-sm font-medium text-red-500">{error}</p> <p className="mt-2 text-sm font-medium text-red-500">{error}</p>
)} )}
@ -252,14 +274,6 @@ export function SubmitProjectModal(props: SubmitProjectModalProps) {
{successMessage} {successMessage}
</p> </p>
)} )}
<button
type="submit"
className="mt-2 w-full rounded-lg bg-black p-2 font-medium text-white disabled:opacity-50"
disabled={isLoading}
>
{isLoading ? 'Verifying...' : 'Verify Submission'}
</button>
</form> </form>
<button <button

Loading…
Cancel
Save