diff --git a/resource/interface/client/alert.lua b/resource/interface/client/alert.lua index 8af45e9..8531c4f 100644 --- a/resource/interface/client/alert.lua +++ b/resource/interface/client/alert.lua @@ -1,14 +1,23 @@ +local alert = nil + function lib.alertDialog(data) + if alert then return end + alert = promise.new() + SetNuiFocus(true, true) SendNUIMessage({ action = 'sendAlert', data = data }) + + return Citizen.Await(alert) end -RegisterNUICallback('closeAlert', function(_, cb) +RegisterNUICallback('closeAlert', function(data, cb) cb(1) SetNuiFocus(false, false) + alert:resolve(data) + alert = nil end) RegisterNetEvent('ox_lib:alertDialog', lib.alertDialog) diff --git a/web/src/features/dialog/AlertDialog.tsx b/web/src/features/dialog/AlertDialog.tsx index 3081d32..2e125ac 100644 --- a/web/src/features/dialog/AlertDialog.tsx +++ b/web/src/features/dialog/AlertDialog.tsx @@ -19,6 +19,7 @@ interface DialogProps { header: string; content: string; centered?: boolean; + cancel?: boolean; } debugData([ @@ -28,6 +29,7 @@ debugData([ header: "Hello there", content: "General kenobi \n Markdown works", centered: true, + cancel: true, }, }, ]); @@ -41,9 +43,9 @@ const AlertDialog: React.FC = () => { content: "", }); - const closeAlert = () => { + const closeAlert = (button: string) => { onClose(); - fetchNui("closeAlert"); + fetchNui("closeAlert", button); }; useNuiEvent("sendAlert", (data: DialogProps) => { @@ -59,7 +61,7 @@ const AlertDialog: React.FC = () => { isOpen={isOpen} isCentered={dialogData.centered} closeOnOverlayClick={false} - onEsc={closeAlert} + onEsc={() => closeAlert("cancel")} > @@ -70,7 +72,17 @@ const AlertDialog: React.FC = () => { {dialogData.content} - + {dialogData.cancel && ( + + )} + diff --git a/web/src/providers/LocaleProvider.tsx b/web/src/providers/LocaleProvider.tsx index afb8706..835b304 100644 --- a/web/src/providers/LocaleProvider.tsx +++ b/web/src/providers/LocaleProvider.tsx @@ -47,6 +47,7 @@ interface Locale { title: string; language: string; }; + cancel: string; close: string; confirm: string; }; @@ -67,6 +68,7 @@ const LocaleProvider: React.FC = ({ children }) => { title: "", language: "", }, + cancel: "", close: "", confirm: "", },