-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1 parent
c248c35
commit 9c9d1cc
Showing
15 changed files
with
262 additions
and
8 deletions.
There are no files selected for viewing
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,2 +1,3 @@ | ||
User-Agent: * | ||
Allow: / | ||
Disallow: /admin/ |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import axios from "axios"; | ||
|
||
export type InvitationResponse = { | ||
status: boolean; | ||
error: string; | ||
quota: number; | ||
} | ||
|
||
export async function getInvitation(code: string): Promise<InvitationResponse> { | ||
try { | ||
const resp = await axios.get(`/invite?code=${code}`); | ||
return resp.data as InvitationResponse; | ||
} catch (e) { | ||
console.debug(e); | ||
return { status: false, error: "network error", quota: 0 }; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
} from "../components/ui/dialog.tsx"; | ||
import { Button } from "../components/ui/button.tsx"; | ||
import { useTranslation } from "react-i18next"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { | ||
closeDialog, | ||
dialogSelector, | ||
setDialog, | ||
} from "../store/invitation.ts"; | ||
import { Input } from "../components/ui/input.tsx"; | ||
import { useToast } from "../components/ui/use-toast.ts"; | ||
import {useState} from "react"; | ||
import {getInvitation} from "../conversation/invitation.ts"; | ||
|
||
function Invitation() { | ||
const { t } = useTranslation(); | ||
const dispatch = useDispatch(); | ||
const open = useSelector(dialogSelector); | ||
const { toast } = useToast(); | ||
const [code, setCode] = useState(""); | ||
|
||
return ( | ||
<Dialog open={open} onOpenChange={(open) => dispatch(setDialog(open))}> | ||
<DialogContent> | ||
<DialogHeader> | ||
<DialogTitle>{t("invitation.title")}</DialogTitle> | ||
<DialogDescription> | ||
<Input | ||
value={code} | ||
placeholder={t("invitation.input-placeholder")} | ||
className={`w-full mt-6 text-center`} | ||
onChange={(e) => setCode(e.target.value)} | ||
/> | ||
</DialogDescription> | ||
</DialogHeader> | ||
<DialogFooter> | ||
<Button variant={`outline`} onClick={() => dispatch(closeDialog())}> | ||
{t("invitation.cancel")} | ||
</Button> | ||
<Button onClick={async () => { | ||
const resp = await getInvitation(code.trim()); | ||
if (resp.status) { | ||
toast({ | ||
title: t("invitation.check-success"), | ||
description: t("invitation.check-success-description", { amount: resp.quota }), | ||
}) | ||
dispatch(closeDialog()); | ||
} | ||
else toast({ | ||
title: t("invitation.check-failed"), | ||
description: resp.error, | ||
}) | ||
}}> | ||
{t("invitation.check")} | ||
</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} | ||
|
||
export default Invitation; |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {createSlice} from "@reduxjs/toolkit"; | ||
import {RootState} from "./index.ts"; | ||
|
||
export const invitationSlice = createSlice({ | ||
name: "invitation", | ||
initialState: { | ||
dialog: false, | ||
}, | ||
reducers: { | ||
toggleDialog: (state) => { | ||
state.dialog = !state.dialog; | ||
}, | ||
setDialog: (state, action) => { | ||
state.dialog = action.payload as boolean; | ||
}, | ||
openDialog: (state) => { | ||
state.dialog = true; | ||
}, | ||
closeDialog: (state) => { | ||
state.dialog = false; | ||
}, | ||
} | ||
}); | ||
|
||
export const {toggleDialog, setDialog, openDialog, closeDialog} = invitationSlice.actions; | ||
export default invitationSlice.reducer; | ||
|
||
export const dialogSelector = (state: RootState): boolean => state.invitation.dialog; |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cli | ||
|
||
func Run() bool { | ||
args := GetArgs() | ||
if len(args) == 0 { | ||
return false | ||
} | ||
|
||
switch args[0] { | ||
case "help": | ||
Help() | ||
return true | ||
case "invite": | ||
CreateInvitationCommand(args[1:]) | ||
return true | ||
default: | ||
return false | ||
} | ||
} |
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,13 @@ | ||
package cli | ||
|
||
import "fmt" | ||
|
||
var Prompt = ` | ||
Commands: | ||
- help | ||
- invite <type> <num> <quota> | ||
` | ||
|
||
func Help() { | ||
fmt.Println(fmt.Sprintf("%s", Prompt)) | ||
} |
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,25 @@ | ||
package cli | ||
|
||
import ( | ||
"chat/auth" | ||
"chat/connection" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
func CreateInvitationCommand(args []string) { | ||
db := connection.ConnectMySQL() | ||
|
||
var ( | ||
t = GetArgString(args, 0) | ||
num = GetArgInt(args, 1) | ||
quota = GetArgFloat32(args, 2) | ||
) | ||
|
||
resp, err := auth.GenerateInvitations(db, num, quota, t) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
fmt.Println(strings.Join(resp, "\n")) | ||
} |
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,63 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func GetArgs() []string { | ||
return os.Args[1:] | ||
} | ||
|
||
func GetArg(args []string, idx int) string { | ||
if len(args) <= idx { | ||
log.Fatalln(fmt.Sprintf("not enough arguments: %d", idx)) | ||
} | ||
return args[idx] | ||
} | ||
|
||
func GetArgInt(args []string, idx int) int { | ||
i, err := strconv.Atoi(GetArg(args, idx)) | ||
if err != nil { | ||
log.Fatalln(fmt.Sprintf("invalid argument: %s", err.Error())) | ||
} | ||
return i | ||
} | ||
|
||
func GetArgFloat(args []string, idx int, bitSize int) float64 { | ||
f, err := strconv.ParseFloat(GetArg(args, idx), bitSize) | ||
if err != nil { | ||
log.Fatalln(fmt.Sprintf("invalid argument: %s", err.Error())) | ||
} | ||
return f | ||
} | ||
|
||
func GetArgFloat32(args []string, idx int) float32 { | ||
return float32(GetArgFloat(args, idx, 32)) | ||
} | ||
|
||
func GetArgFloat64(args []string, idx int) float64 { | ||
return GetArgFloat(args, idx, 64) | ||
} | ||
|
||
func GetArgBool(args []string, idx int) bool { | ||
b, err := strconv.ParseBool(GetArg(args, idx)) | ||
if err != nil { | ||
log.Fatalln(fmt.Sprintf("invalid argument: %s", err.Error())) | ||
} | ||
return b | ||
} | ||
|
||
func GetArgInt64(args []string, idx int) int64 { | ||
i, err := strconv.ParseInt(GetArg(args, idx), 10, 64) | ||
if err != nil { | ||
log.Fatalln(fmt.Sprintf("invalid argument: %s", err.Error())) | ||
} | ||
return i | ||
} | ||
|
||
func GetArgString(args []string, idx int) string { | ||
return GetArg(args, idx) | ||
} |
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